Jump to content

query problem


fortnox007

Recommended Posts

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. :(

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

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.