Page 1 of 1

MySQL query insert command syntax error 42000

Posted: Sun Nov 30, 2014 5:42 am
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?

Re: MySQL query insert command syntax error 42000

Posted: Sun Nov 30, 2014 7:43 am
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!