Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

MySQL is accepting my insert query but PHP is retuning error

Codes here !

Moderators: macek, egami, gesf

MySQL is accepting my insert query but PHP is retuning error

Postby randdnar » Tue May 13, 2014 10:33 pm

I'm new to writing PHP with MySQL and this one has me stumped. I've setup a page with some input fields that on submit converts it into a MySQL INSERT query and run it to the db. Everything was working fine, until I entered some text with a single quote and discovered MySQL doesn't like that. No problem, I just added a quick replace:

Code: Select all
str_replace('\'', '\\\'', $description)


So that "wasn't" becomes "wasn\'t" in the string, so that it does. And when I check in the MySQL console it does post the line to he db, but in my browser PHP returns the error:

Query: INSERT INTO timecard (name,customer,projectno,year,period,day, totaltime,fromtime,totime,description) VALUES ('Randy', 'Customer',11,2014,09,13,'01:00:00','12:00:00','13:00:00','Apache wasn\'t running correctly but has now been fixed ')
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 't running correctly but has now been fixed ')' at line 4


How do I get around this? If I recall correctly adding # in front of a line will make the browser skip any warnings or errors, but that would be a horrible idea for a MySQL Query error. Seems like I'm missing something obvious here but 'Google it' hasn't turned up any answers for me.

Any help would be appreciated, thanks.
randdnar
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue May 13, 2014 10:13 pm

Return to mySQL & php coding

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.