fortnox007 Posted January 20, 2011 Share Posted January 20, 2011 Hi all, Could someone have a look at the stuff below. I am able to show the $_POST variables, but from the moment i use mysqli_real_escape_string it goes wrong ( as in the variable seems empty) // mysqli connection file is above here // $clean_name = mysqli_real_escape_string(trim($_POST['name'])); $clean_email = mysqli_real_escape_string(trim($_POST['email'])); echo 'clean_name = '.$clean_name; //outputs noting echo 'clean_email = '.$clean_email; //outputs noting $query_control = "SELECT email FROM my_table WHERE email = $clean_email"; $result = mysqli_query($dbc, $query_control)or die(mysqli_error($con)); // <------- spotted: should have been $dbc //check for duplicates $number = mysqli_num_rows($result); echo $number; if($number === 0){ $output = 'valid'; }else{ $errormessage .= 'duplicate entry'; } } any help would be welcome edit- Oh i spotted some stuff (after changing it becamce: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1) But not able to fix it really. Quote Link to comment https://forums.phpfreaks.com/topic/225069-query-problem/ Share on other sites More sharing options...
fortnox007 Posted January 20, 2011 Author Share Posted January 20, 2011 I changed the code a little by placing ' ' around $clean_email in the query which caused the sql error to stop. But for some reason i don't get why, $clean_name and $clean_email seem to be empty?? Quote Link to comment https://forums.phpfreaks.com/topic/225069-query-problem/#findComment-1162473 Share on other sites More sharing options...
PFMaBiSmAd Posted January 20, 2011 Share Posted January 20, 2011 Using mysqli_real_escape_string() procedurally, requires the connection link as a parameter. If you were developing and debugging your code on a system with error_reporting set to E_ALL (or a -1) and display_errors set to ON, php would help you by reporting and displaying all the errors it detects. You will save a TON of time. There would be error(s) when you called mysqli_real_escape_string() because of the incorrect parameters. Quote Link to comment https://forums.phpfreaks.com/topic/225069-query-problem/#findComment-1162475 Share on other sites More sharing options...
fortnox007 Posted January 20, 2011 Author Share Posted January 20, 2011 Thanks alot PFMaBiSmAd, sorry for not using the error reporting, i was in a bit of a hurry, and was developing directly on the host instead of local. Seems it would have taken me less time if i would have just listened to common sense Thanks for your reply, i'll try it out and mark this solved cheers! Quote Link to comment https://forums.phpfreaks.com/topic/225069-query-problem/#findComment-1162477 Share on other sites More sharing options...
fortnox007 Posted January 20, 2011 Author Share Posted January 20, 2011 great help and sorry for my noobiness i placed error_reporting(E_ALL); ini_set("display_errors", 1); above my file and i directly got what i wanted (error wise ) Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in /blablabla on line 31 Thanks mate! P.s. i added it to my forum signature so i will never forget ty Quote Link to comment https://forums.phpfreaks.com/topic/225069-query-problem/#findComment-1162479 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.