Jump to content

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


cluce

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.