Jump to content

PHP/MySQL unexpected results


pcwood

Recommended Posts

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\">&nbsp;\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?
Link to comment
Share on other sites

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