SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: update query

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2004
    Location
    Boston
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    update query

    I keep getting an error when i use this update query.

    can someone help me please.

    update `table` set `column1` = '$varvalue' WHERE `column2` = 'value1' AND `column1`='value2'

    for some reason it doesnt work when I put the AND in there and the second column value.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    looks okay to me

    what error message did you get?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2004
    Location
    Boston
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have an error in your SQL syntax near 'date`= '1'' at line 1

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    you have a column called date? that's a reserved word, and you are right to enclose it in backticks

    why are you looking for a string in it?

    can we see the full query and also the CREATE TABLE statement?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Evangelist
    Join Date
    Apr 2004
    Location
    Boston
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the table is already created i just need it to update.

    here is the query:

    $getnewdate = "UPDATE `test_track` SET `date`='$date' WHERE `cat='$cat' AND `date`= '$mindate'";

    Let me explain what I am trying to do.

    I run a school for court reporters. I'm setting up this site as a way to stream their practice and testing materials.

    I have the date column set as INT and a query that grabs the MIN(date) and updates it to todays date then the next page pulls the 2 rows where the value of the date column=$date (todays date) by date and by category.

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    you're missing the closing backtick here --> WHERE `cat='$cat'

    tip: don't use backticks if you don't have to

    tip: do use backticks where you do have to, like around reserved words used as column names

    tip: don't assign strings to numeric columns

    tip: use DATE datatype if you really want to store dates
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Evangelist
    Join Date
    Apr 2004
    Location
    Boston
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its not so much that i needed to store the date itself I just need to update the lowest value everyday and pull the info from that updated field.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •