pcwood Posted October 12, 2006 Share Posted October 12, 2006 Greetings,I'm using a familiar formula to retrieve and check results from a mysql db. However, I'm stuck on a response I haven't seen before. Perhaps someone can tell me why I'm getting the response I am. TIA:[color=blue][/color]<?PHP// if the user hit the submit button and filled the email field then ...if(isset($_POST['submit']) && $email != "") { // Check db for existence of user $link = mysql_connect ("localhost", "the_admin", "my_password"); if(!$link) { echo "Database Connect Error: " . mysql_error() . "<BR>Please contact our company or try back later."; } // Select the database $selectResponse = mysql_select_db ("the_database", $link); if(!$selectResponse) { echo "Database Select Error. Please contact our company or try back later."; } // Make the SQL statement call $query = sprintf("SELECT Cemail, Ccqrt_question, Ccqrt_answer FROM customer_data WHERE Cemail='%s'", mysql_real_escape_string($email)); $result = mysql_query($query, $link); echo "Query: $query<P>\n"; echo "Result: [$result]<BR>Error:" . mysql_error() . "<P>"; if(!$result) { echo "Customer [$email] was not found to be on record. Please check your spelling and try again or "; echo "<A HREF=\"custREG.htm\">create a new account</A>. Thank you."; } else { $row = mysql_fetch_row($result); $Cemail = $row[0]; $Ccqrt_question = $row[1]; $Ccqrt_answer = $row[2]; echo "Security Question: $Ccqrt_question<P>\n"; echo "<INPUT TYPE=\"text\" SIZE=\"50\" MAXLENGTH=\"50\" NAME=\"answer\"><P>\n"; echo "I cannot remember this either. Please just reset my password and email it to me.\n"; } mysql_close($link); } else { echo "Enter your username (email address)<BR>\n"; echo "<INPUT TYPE=\"text\" SIZE=\"50\" MAXLENGTH=\"40\" NAME=\"email\"><BR>\n"; echo "<INPUT TYPE=\"reset\" NAME=\"Reset\" VALUE=\"Reset Form\"> \n"; echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"submit\">\n";}?>[color=black][/color]NOTE: This is, of course, incomplete and I have ECHOs embeded to help me figure what's going on. Here is what I get when I put either a good or or bad query in:[color=red][/color]Query: SELECT Cemail, Ccqrt_question, Ccqrt_answer FROM customer_data WHERE Cemail='s.austin@megabucks.com'Result: [Resource id #2]Error:[color=black][/color]I've done this many times before without fail. Can anyone see the problem? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 12, 2006 Share Posted October 12, 2006 Your assumption that $result is false if there are no records found is causing the problem. Not finding any records which match the WHERE criteria is not an error therefor $result will still have a valid resource value. Quote Link to comment Share on other sites More sharing options...
pcwood Posted October 14, 2006 Author Share Posted October 14, 2006 So shall I assume $result ==0 is the point of failure? Does this ONLY occur with the WHERE clause? If so, why?Example Code from php.net looks like this:[color=blue][/color]<?php$result = mysql_query('SELECT * WHERE 1=1');if (!$result) { die('Invalid query: ' . mysql_error());}?>[color=black][/color]How have I changed the outcome?Thanks for the response.-PCWOOD Quote Link to comment Share on other sites More sharing options...
Barand Posted October 14, 2006 Share Posted October 14, 2006 $result = mysql_query('SELECT * WHERE 1=1');That query returns "false" because it has a syntax error (no FROM clause) Quote Link to comment 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.