hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Simple MySQL/PHP error
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Simple MySQL/PHP error

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 04-21-2011, 10:37 PM
wesslayneb wesslayneb is offline
Newbie
 
Join Date: Jan 2011
Posts: 8

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:

Quote:
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!

Reply With Quote


Sponsored Links
  #2  
Old 04-21-2011, 10:41 PM
kjsrs kjsrs is offline
Junior Guru Wannabe
 
Join Date: Jan 2010
Location: MT
Posts: 45
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.

Reply With Quote
  #3  
Old 04-21-2011, 10:42 PM
quantumphysics quantumphysics is offline
MACBOOKS EVERYWHEREEEEEEEEEEEE
 
Join Date: Mar 2009
Posts: 3,804
use pdo or something

__________________
mirACL: firewalls in software.

Reply With Quote
Sponsored Links
  #4  
Old 04-21-2011, 10:45 PM
wesslayneb wesslayneb is offline
Newbie
 
Join Date: Jan 2011
Posts: 8
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.

Reply With Quote
  #5  
Old 04-21-2011, 10:49 PM
wesslayneb wesslayneb is offline
Newbie
 
Join Date: Jan 2011
Posts: 8
But by some magic it actually worked. The missing backticks were the smoking gun there, lol. Thanks a lot.

Reply With Quote
  #6  
Old 04-22-2011, 06:09 AM
alanversowa alanversowa is offline
New Member
 
Join Date: Apr 2011
Posts: 2
Nice can you discuss some sorts of magic here ?

Reply With Quote
  #7  
Old 04-22-2011, 08:40 AM
Sajid-HostX10 Sajid-HostX10 is offline
Aspiring Evangelist
 
Join Date: Apr 2009
Posts: 406
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 - CEO - HostX10 - Reliable Hosting
Email: sajid[at]hostx10[dot]com
Shared | Reseller | Master Reseller
HostX10.com - Premium Web Hosting


Reply With Quote
  #8  
Old 04-22-2011, 09:42 AM
speckl speckl is offline
Web Hosting Evangelist
 
Join Date: Jan 2004
Posts: 532
http://dev.mysql.com/doc/refman/5.1/...ved-words.html

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.

Reply With Quote
  #9  
Old 04-22-2011, 02:59 PM
wesslayneb wesslayneb is offline
Newbie
 
Join Date: Jan 2011
Posts: 8
Yes, the magic I mentioned before worked, the second way kjsrs mentioned. And thanks, speckl, now I can understand why it didn't work.

Reply With Quote
Reply

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

Related posts from TheWhir.com
Title Type Date Posted
French Web Host Gandi Expands Platform as a Service to US Market Web Hosting News 2012-07-09 10:40:52
Web Host Rackspace Launches Private Beta for MySQL Cloud Database Web Hosting News 2011-12-01 21:09:51
Parallels Now Offering Licenses for CloudLinux OS Web Hosting News 2011-10-26 17:29:25
Web Hosting Software Firm CloudLinux Releases CloudLinux OS Version 6.1 Web Hosting News 2011-09-13 14:08:49
Web Host FireHost Partners with Cloud Security Firm Gazzang for Data Encryption Web Hosting News 2011-08-16 20:33:43


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?