Results 1 to 9 of 9
  1. #1

    Simple MySQL/PHP error

    Alright, I've been coding in PHP and MySQL for about a year now and I feel like I've done this very query a million times, but all day today I've been running into errors.

    The table name is title_transfers, the column I'm editing is read, and the column to represents the person receiving a transfer. $userfinal is the session name. If the "read" column is "no", a notification appears on the home page, alerting the user of a transfer to him/her. When they view the page the following code is at the top of, the read column of any transfer to that person is changed to "yes" so that the notification no longer appears on the home page. The code is as follows:

    PHP Code:
    mysql_query("UPDATE title_transfers SET read=yes WHERE to=$userfinal") or die(mysql_error()); 
    The error I've been receiving:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read=yes WHERE to=RapideGT' at line 1
    RapideGT is the test username/session name. I've tried everything; I can't understand why it's not working. I've noticed this type of thing happening a lot after I upgrade to VPS, if that helps. Any input is appreciated!

  2. #2
    Join Date
    Jan 2010
    You need to quote your inputs when they are not numerical. Try this instead:

    PHP Code:
    mysql_query("UPDATE title_transfers SET read='yes' WHERE to='$userfinal'") or die(mysql_error()); 
    It's also good practice to quote your table and field names with backticks too:

    PHP Code:
    mysql_query("UPDATE `title_transfers` SET `read`='yes' WHERE `to`='$userfinal'") or die(mysql_error()); 
    Shout! Radio Services
    Developer of Shout! Radio Automation
    Complete cloud-based radio station automation.

  3. #3
    Join Date
    Mar 2009
    use pdo or something

  4. #4
    I did use quotes at first, but after viewing several tutorial websites to see if I did anything wrong, most did not have them so I tried without, for kicks and giggles. No luck there, obviously.

    And I have no idea what PDO is.

  5. #5
    But by some magic it actually worked. The missing backticks were the smoking gun there, lol. Thanks a lot.

  6. #6
    Nice can you discuss some sorts of magic here ?

  7. #7
    Join Date
    Apr 2009
    Did it work ? It should but if not try this:

    PHP Code:
    mysql_query("UPDATE `title_transfers` SET `read`='yes' WHERE `to` = '".$userfinal."'") or die(mysql_error()); 
    Sajid Iftekhar - Web Design Portfolio

  8. #8
    Join Date
    Jan 2004

    Read and to are reserved words. It would only work with backticks or tablename.columnname format.

    I recommend changing the column names because you will eventually run into more issues.

  9. #9
    Yes, the magic I mentioned before worked, the second way kjsrs mentioned. And thanks, speckl, now I can understand why it didn't work.

Similar Threads

  1. PHP - Mysql Error during query, help out with a simple problem? :)
    By optimumd in forum Programming Discussion
    Replies: 12
    Last Post: 06-30-2006, 02:00 PM
  2. Simple MySQL error question
    By simcoweb in forum Programming Discussion
    Replies: 7
    Last Post: 09-14-2005, 02:42 AM
  3. PHP - simple error.
    By DLevit in forum Programming Discussion
    Replies: 2
    Last Post: 02-12-2005, 06:08 AM
  4. very simple php error
    By Georgecooldude in forum Hosting Security and Technology
    Replies: 13
    Last Post: 02-11-2005, 07:15 AM

Posting Permissions

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