Re: Mysql statement works in phpmyadmin but not in php page

From: Date: Thu, 11 Feb 2010 21:42:18 +0000
Subject: Re: Mysql statement works in phpmyadmin but not in php page
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-302020@lists.php.net to get a copy of this message
Thank you. You were right on the money, "hour" was the problem and the tick marks solved it. I spent 3 hours trying to figure out why I never got an error but there was no insert and php myadmin does add the tick marks automatically. Probably a good habit to always use the tick marks. Learn something new everyday. On Thu, Feb 11, 2010 at 4:26 PM, Joseph Thayne <webadmin@thaynefam.org>wrote: > Try putting tick marks (`) around the field and table names. So your SQL > query would then look like: > > > INSERT INTO history (v_id, > hour, visits, > date) VALUES (45, 0, 59, > '2010 01 27'); > > This is a good practice to get into. The problem is that MySQL allows you > to create tables and fields with the same name as functions. If the tick > marks are not there, then it assumes you mean to try using the function. In > your case, hour is a function in mysql. I would assume that the reason it > works in phpmyadmin is that it filters the query somehow to add the tick > marks in. > > Joseph > > > james stojan wrote: > >> I'm at my wits end trying to make this mysql statement insert work in >> PHP. I'm not getting any errors from PHP or mysql but the insert fails >> (nothing is inserted) error reporting is on and is reporting other >> errors. When I echo out the query and manually paste it into PHP >> myAdmin the query inserts without a problem. I know that I am >> connecting to the database as well part of the data being inserted >> comes from the same database and that the mysql user has permission to >> do inserts (even tried as root no luck). >> >> $query="INSERT INTO upload_history (v_id,hour,visits,date) VALUES >> >> (".$v_id.",".$hour.",".$visits.",'$date1'".");"; >> >> $r2=mysql_query($query) or die("<b>A fatal MySQL error >> occured</b>.\n<br />Query: " . $query . "<br />\nError: (" >> . >> mysql_errno() . ") " . mysql_error()); >> >> This is an echo of $query and runs in phpmyadmin. >> >> INSERT INTO history (v_id,hour,visits,date) VALUES (45,0,59,'2010 01 27'); >> >> >> Any idea what is going on here? >> >> >> >

« previous php.general (#302020) next »