Re: [PHP] Mysql statement works in phpmyadmin but not in php page

[email protected] (Joseph Thayne)
Newsgroups php.general
Message-ID <[email protected]>
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?
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.