Boerboel649 Posted April 11, 2007 Share Posted April 11, 2007 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! Link to comment https://forums.phpfreaks.com/topic/46630-getting-rid-of-the-single-quote-apostrophe-error-when-putting-values-into-mysql/ Share on other sites More sharing options...
paul2463 Posted April 11, 2007 Share Posted April 11, 2007 <a href="http://uk3.php.net/addslashes" > Add Slashes - do it by looking here </a> <a href="http://uk3.php.net/mysql_escape_string" > Real Escape String - do it by looking here </a> Link to comment https://forums.phpfreaks.com/topic/46630-getting-rid-of-the-single-quote-apostrophe-error-when-putting-values-into-mysql/#findComment-227048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.