Jump to content

[SOLVED] apostrophe causes SQL error with database insert


webguync

Recommended Posts

I am developing a form, where people login and fill out some checkboxes. The name and checkbox info is inserted into a MySQL DB. If someone has an apostrophe in their name like O'Neil, this throws and error when they submit. I believe the apostrophe is causing the error. How can I  apostrophe proof the name field?

thanks, I added the function here, but there is a syntax error somewhere. Also, can I just use the whole $insert instead of doing each field individually?

 

  $insert = "INSERT INTO $check_table (`Assessor`,`AssessorID`,`EmpName`,`EmpID`, `Blocks`,`date_uploaded`) VALUES ('$Assessor','$Assessor_ID','$name','$emp_id', '$blocks', '$now')";
  mysql_query($insert) or die(mysql_error()),
  mysql_real_escape_string($Assessor),
  mysql_real_escape_string($Assessor_ID));

You need to use it on the variables being inserted:

<?php
$insert = "INSERT INTO $check_table (`Assessor`,`AssessorID`,`EmpName`,`EmpID`, `Blocks`,`date_uploaded`) VALUES ('" . mysql_real_escape_string($Assessor) . "','" . mysql_real_escape_string($Assessor_ID) . "','" . mysql_real_escape_string($name) . "','" . mysql_real_escape_string($emp_id) . "', '" . mysql_real_escape_string($blocks) . "', '" . mysql_real_escape_string($now) . "')";
$ rs = mysql_query($insert) or die("Problem with the query: $insert<br>" . mysql_error());
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.