Jump to content

Getting rid of the single quote/ apostrophe error when putting values into MySQL


Boerboel649

Recommended Posts

Hi all,

I have a form which places values into a MySQL DB. On this form, one of the input boxes is for height, in which we use single quotes/ apostrophes (eg 6' 3")

 

However, whenever you try to do the single quote/apostrophe and submit it, it MySQL gives an error. I was wondering if there was some way to get it to work without always having to type in a backlsash before the single quote. What PHP code can I use to make this work?

 

Here's the code that submits the form:

 

<?
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$nickname = $_POST['nickname'];
$number = $_POST['number'];
$position = $_POST['position'];
$height = $_POST['height'];
$weight = $_POST['weight'];
$other = $_POST['other'];
  $query = "INSERT INTO players (fname, lname, nickname, number, position, height, weight, other)";
  $query .= "VALUES('$fname', '$lname', '$nickname', '$number', '$position', '$height', '$weight', '$other')";
  mysql_query($query, $dbh) or die("MySQL Error: The following errors have been encountered.  If you cannot resolve this issue, please contact the webmaster. <br /> {$query} <br /> ". mysql_error());
  echo "You have successfully completed the following: $query"; 

?>

 

 

Thanks!

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.