Jump to content

[SOLVED] not sure if query is getting correct value from database


Recommended Posts

Can someone tell me if I have any errors in this code?  For some reason it goes to the error page everytime, even though it has a value of 0 in the column confirmkey.  I am able to update the field 0 or 1 for confirmkey at the approriate places in my code but this if condition is not working like it should.  If confirm key is 0 its supposed to execute the rest of the code and if its a 1 its supposed to go to the error page.  can someone tell me if I did this query right?

 

//gets query for confirm key 
$checkemail = trim(strip_tags($_POST['email']));
$sql0 = "SELECT Confirmkey FROM auth_users WHERE email = '$checkemail' LIMIT 1";
$key = mysqli_query($mysqli, $sql0);

if ($key == 1) {
  header("Location: ../error.html");
  exit();
}	

not sure about mysqli at all but can you put in the "or die" phrase just like mysql such as

 

//gets query for confirm key 
$checkemail = trim(strip_tags($_POST['email']));
$sql0 = "SELECT Confirmkey FROM auth_users WHERE email = '$checkemail' LIMIT 1";
$key = mysqli_query($mysqli, $sql0) or die ("error in query" . mysqli_error()); //this bit to see if there is an error thrown??

if ($key == 1) {
  header("Location: ../error.html");
  exit();
}	

the return from mysqli_query() is a RESOURCE.  you must then parse this resource with an extraction function to obtain the actual resultset returned by the query that you've run.

 

think of mysql_query() as telling you where in a file cabinet to look for a document; you must then use something like mysql_result() or mysql_fetch_array() or a similar extraction function to actually grab the document from that file cabinet.

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.