Jump to content
Larry Ullman's Book Forums

Recommended Posts

Ive adapted this script and it seems to work very well, apart from the following error

 

 

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\phpfinal\edit_usersllph.php on line 54

 

I think I understand what the line is trying to do. Larry explains it very well in the book. So I dont get why its going wrong.

Can anyone help? It doesnt stop the script and the changes are made.

 

Here is the code again.

 

 

$q = "SELECT customerID, cardholdersaddress FROM llphorders WHERE customerID = $id AND cardholdersaddress = $ln";

$r = @mysqli_query($dbc, $q);

 

 

if (mysqli_num_rows($r) == 0) {

 

// Make the query:

$q = "UPDATE llphorders SET cardholdersaddress='$ln' WHERE customerID= $id LIMIT 1";

$r = @mysqli_query ($dbc, $q);

if (mysqli_affected_rows($dbc) == 1) { // If it ran OK.

 

// Print a message:

echo '<p>The user has been edited.</p>';

 

} else { // If it did not run OK.

echo '<p class="error">The user could not be edited due to a system error. We apologize for any inconvenience.</p>'; // Public message.

echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; // Debugging message.

}

 

} else { // Already registered.

echo '<p class="error">The email address has already been registered.</p>';

}

 

} else { // Report the errors.

 

 

 

I hope my changes look ok!

 

 

Bill

Link to comment
Share on other sites

Yes, thanks, I went through it again, found a couple of (what I thought were) minor things and uploaded it. The problem didnt appear. In fact it all went better than I expected!

 

Ill now try something else I dont know enough about, and see if I can make that work! I must be getting old (64) because I am actually enjoying all the frustrations and eventual problem solving.

 

Thanks again.

  • Upvote 1
Link to comment
Share on other sites

Well i think that 64 is only a bit older than middle aged, there was a guy last week 97 that just got another degree, but he quoted that it might be his last. ^_^ The best way to keep yourself young is just to keep learning, and that way keeping the brain active. There was also study on TV about how Table Tennis was a safe sport for older people and help to keep them mentally focused.

Link to comment
Share on other sites

mysqli_num_rows will report a boolean false if the query fails. Looks like in your case it is because you don't have quotes around the variable $ln in the first query.

 

Sshhh, don't tell anyone. Just Kidding, thanks for pointing that out, i have myself confused with another function, definitely won't make that mistake again.

Link to comment
Share on other sites

Thanks yet again! Ive looked again and it seems I have included quotes on the variable. My marginal error was decimated! If I could 'get' curly braces, Id be home and dry, Im sure.

but thats another story (or thread...)

Link to comment
Share on other sites

In your first query, there are no quotes around $ln, which is a string and should be quoted. You had:

$q = "SELECT customerID, cardholdersaddress FROM llphorders WHERE customerID = $id AND cardholdersaddress = $ln";

 

What you need to do is add single-quotes around just $ln:

$q = "SELECT customerID, cardholdersaddress FROM llphorders WHERE customerID = $id AND cardholdersaddress = '$ln' ";

 

That will tell MySQL that you are submitting string data to that field. Without the single-quotes, MySQL will assume you are submitting numeric values, which won't fit the datatype and the query will fail. You correctly had the single-quotes in your second query:

$q = "UPDATE llphorders SET cardholdersaddress='$ln' WHERE customerID= $id LIMIT 1";

 

Curly braces wouldn't help in this case. You weren't getting a PHP error, the problem was with the syntax of the SQL query.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...