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.