PDA

View Full Version : mysql_num_rows(): error


ryanschefke
04-13-2004, 06:56 PM
Can anyone help me here. I'm making two MySQL queries. The MySQL query in the middle works fine standalone (in red). However, when I add another MySQL query on top (in blue) I'm getting the error below when the query in the middle (in red) executes:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Apache\Apache2\html\tgwedding\TMPpcyr9w49u2.php on line 101




<?php
echo $login_ck;
////////// query the database for sticky form
require_once ("mysql_connect.php");
$query = "SELECT * FROM customers WHERE accountName='$login_ck'";
$result = @mysql_query($query); // run the query
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);//store this record as an array "row"
mysql_free_result($result);
echo $row['email'];
}
mysql_close(); // close the db connection
////////// end of query for sticky form

////// MAIN CONDITIONAL LOOP //////// begin checking for errors in the script
if (isset($save)) { //handle the form
require_once ("mysql_connect.php");
// connect to the db


....
....
....
....
..... more conditionals

///////////////////////////////////////////////////////////////////////////////////


if ($ap && $fn && $ln && $ad && $ci && $st && $co && $zi) { // if everything is filled out

$query = "SELECT * FROM customers WHERE accountName='$login_ck'";
$result = @mysql_query($query); // run the query
if (mysql_num_rows($result) == 1) { ////////////////////////////////this is where the problem is
$row = mysql_fetch_array($result, MYSQL_ASSOC);//store this record as an array "row"
echo "the 2nd query was successful";

// make the query
$query = "UPDATE customers SET accountPassword='$ap', firstName='$fn', lastName='$ln', address='$ad', city='$ci',
state='$st', country='$co', zipcode='$zi', sitePassword='$wp', personalInfoUpdated=NOW() WHERE customerID=$row[customerID]";
$result = @mysql_query ($query); // run the query
if (($result) AND (mysql_affected_rows() == 1)) { //if the query ran successfully
//do something here.
$message = '<p>Account Update Successfull</p>';

} else { //if it did not run okay
$message = "<p>You could not update your info due to a system error. We apologize for any inconvenience</p><p>" . mysql_error() . "</p>";
}

} else {
$message = '<p>That username is not registered with us. Please sign up.</p>';
}

mysql_close(); // close the db connection.

/////////////////////////////////////////////////////////////////////////////

} else {
$message .= "<p>Please try again</p><br>";
}

} // end of the main conditional loop
?>

raf
04-13-2004, 09:09 PM
Welcome here !

First of, use enclose your code in [php ] and [/php ] tags (without the space) so it's easier to read.

About your problem --> there is no need to close the connection inside your page. You don't even need to close i at all, since it's automatically clodsed when the scriptends.
You have
require_once ("mysql_connect.php");
to open the connection, but, like the name suggests, when using require_once (), the file is includede only once, so the second call (before your red query) will just be ignored. Which means no connection will be opened, which means no recorsdest will be returned etc.