php - string value contains (') in the insert statement. -


i have following insert statement, work fine if pname doesn't have (') value, when text contain of ('), query return syntax error. idea how fix this? many thanks.

$queryinsert = "insert cart (cartpid, cartpname, cartprice,cartcustid, cartdate) values ( $pid, '$pname', $pprice, $custid, (now()))"; 

you need escape inputs before saving in database. example, mysql_real_escape_string.

$pname = mysql_real_escape_string($pname);  $queryinsert = "insert cart (cartpid, cartpname, cartprice,cartcustid, cartdate) values ( $pid, '$pname', $pprice, $custid, (now()))"; 

this kind of situation can lead sql injection, should check topic. first thing move prepared statements, save headache sql injection prevention.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo