derekshull Posted October 19, 2012 Share Posted October 19, 2012 I have the following code below and my problem is that in the description field if someone puts a ' (like when they use can't or won't or don't) it has an error....because it makes it act like the query is ending...how do I fix this? global $user; $needsusername = $user->name; $needsip = $_POST['ip']; $firstname = $_POST['firstname']; $city = $_POST['city']; $state = $_POST['state']; $phone = $_POST['phone']; $email = $_POST['email']; $typeofneed = $_POST['typeofneed']; $description = $_POST['description']; $orgname = $_POST['organizationname']; if (!mysql_query("INSERT INTO needs (firstname, city, state, phone, email, typeofneed, description, needsip, needsusername, orgname) VALUES ('$firstname', '$city', '$state', '$phone', '$email', '$typeofneed', '$description', '$ip', '$needsusername', '$orgname')")) { die('Error: ' . mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/269661-mysql-error-when-text-field-has/ Share on other sites More sharing options...
ManiacDan Posted October 19, 2012 Share Posted October 19, 2012 mysql_real_escape_string. Use it on every single string input. Quote Link to comment https://forums.phpfreaks.com/topic/269661-mysql-error-when-text-field-has/#findComment-1386226 Share on other sites More sharing options...
derekshull Posted October 19, 2012 Author Share Posted October 19, 2012 Where do I need to put that? I very new to php and sql Quote Link to comment https://forums.phpfreaks.com/topic/269661-mysql-error-when-text-field-has/#findComment-1386227 Share on other sites More sharing options...
derekshull Posted October 19, 2012 Author Share Posted October 19, 2012 Nevermind I figured it out. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/269661-mysql-error-when-text-field-has/#findComment-1386230 Share on other sites More sharing options...
JohnTipperton Posted October 20, 2012 Share Posted October 20, 2012 (edited) $needsip = $_POST['ip']; change it to $needsip = mysql_real_escape_string($_POST['ip']); Edited October 20, 2012 by JohnTipperton Quote Link to comment https://forums.phpfreaks.com/topic/269661-mysql-error-when-text-field-has/#findComment-1386518 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.