Jump to content

Problems when ' is entered into input box


cholland

Recommended Posts

Hi All,

 

I have a page where people can enter their name. If they enter a name such as "O'Brien" i get a SQL error when the form is processed and the insert query to the mysql db is run.

 

Does any body have any ideas what's wrong here? Any help would be fantastic!

 

Here is some code from my form with the input boes:

 

<TR><TD></td></tr>
	<tr> 
        <td colspan="2"><h3>Enter Pupil Information (required)</h3></td> 
      </tr> 
        <td width=30%>First Name</td> 
        <td> <input type="text" name="inputFirstName" maxlength="60" size="30" value="" /></td> 
      </tr> 
      <tr>
        <td>Surname</td> 
        <td> <input type="text" name="inputSurName" maxlength="60" size="30" value = "" /></td> 
      </tr> 

 

And here is the form processing when the user clicks save:

 

include ("connect.php");
$theDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : "";
  // create short variable names
  $FirstName=$_POST['inputFirstName'];
  $SurName=$_POST['inputSurName'];
  $AddressLine1=$_POST['inputAddressLine1'];
  $AddressLine2=$_POST['inputAddressLine2'];
  $Town=$_POST['inputTown/City'];
  $HomePhoneNumber=$_POST['inputHomePhoneNumber'];
  $Medical=$_POST['inputMedical'];
  $Interest=$_POST['inputInterest'];


  if (!$FirstName || !$SurName ) {
     echo "You have not entered all the required details.<br />"
          ."Please go back and try again.";
     exit;
} 
else 
{

	mysql_query("INSERT INTO tblpupil (`TeacherID`,`FirstName`, `SurName`,`AddressLine1`,`AddressLine2`,`Town/City`, `HomePhoneNumber`,`DOB`,`Medical`,`Interest`)
					VALUES ('$Sid','$FirstName','$SurName','$AddressLine1','$AddressLine2','$Town','$HomePhoneNumber','$theDate','$Medical','$Interest')") or die(mysql_error());

	echo "Pupil has been added!";
	header('Location: myclass.php');

}	

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.