MySQL query insert command syntax error 42000

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PHPHelpNeeded
Forum Commoner
Posts: 83
Joined: Mon Nov 17, 2014 8:03 pm

MySQL query insert command syntax error 42000

Post by PHPHelpNeeded »

:banghead: I need to find out why the query command is giving me error 42000, which is I think a syntax error:

Code: Select all

                       
                        $this->DBNAME //is the database name magic __get() ".usertable" which is the table to be accessed
                        $p['USER_NAME'] = "myname";
                        $p['USER_PASSWORD'] = crypt_512_encryption("password");

			$insert_result = $this->db_query("INSERT INTO ".$this->DBNAME.".usertable (UserName, UserPassword, UserLastLogin) VALUES (\'".$p['USER_NAME']."\', \'".$p['USER_PASSWORD']."\', \'".date("M:D:Y:H:i:s")."\')");
I wrote this exactly how I see it in a book of PHP and MySQL textbook.

Any idea?
PHPHelpNeeded
Forum Commoner
Posts: 83
Joined: Mon Nov 17, 2014 8:03 pm

Re: MySQL query insert command syntax error 42000

Post by PHPHelpNeeded »

I found the problem.

That happens if one does not use the PDO::quote() function to wrap the values inside quotes.

My problem was that I was escaping the single quotes "\'".$value."\'" thinking it would work that way.

So I changed it to ".$this->quote($value)." that works now, my table is receiving information...great!
Post Reply