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?

Link to comment
Share on other sites

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));

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.