Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in
<?php
require('connect.php');
$id = $_GET['id'];
$code = $_GET['code'];
if ($id&&$code)
{
$check = mysql_query("SELECT * FROM users WHERE id='$id' AND random='$code'");
$checknum = mysql_num_rows($check);
if ($checknum==1)
{
//run a query to activate the account
$acti = mysql_query("UPDATE users SET activated='1' WHERE id='$id'");
die("Your account is activated. You may now log in.");
}
else
die("Invalid ID or Activation code.");
}
else
die("Data missing!");
?>
This is the code I’m not to sure how to fix the problem I tried echo but it does not post any thing.
That error indicates the query ended with an error.
Try this:
$query = "SELECT * FROM users WHERE id='$id' AND random='$code'"
$check = mysql_query($query) or die("mysql error " . mysql_error() . " in query: $query");
Yes, probably it never enters the while loop. Which means it doesn’t find any rows.
Again, try echoing the query to see if it is as you expect (my guess is $user has no value).
You dont need to define $admin before the loop; however the query, as guido pointed out, returns a 0-row set. Do you have any entries in the adminusers table?
Because the idea was that he was supposed to be echoing something - you CAN set admin to ‘’, but there’s no real need for $admin if the script is just going to echo, because you’d just put the echo inside the while loop.
$get = mysql_query("SELECT * FROM adminusers WHERE username='$user'");
while ($row = mysql_fetch_assoc($get)) {
echo $row['admin'];
}
For that matter, why is the while loop there at all? If there’s just going to be one record, then run the code outside of a loop. If there’s going to be more than one, dont set $admin = because it will just overwrite every time the loop iterates.
$admin needs to be defined as an array if you intend on using it with a foreach loop, otherwise if there are no matches the foreach will see a normal variable and not an array.
$q = "SELECT notes FROM users WHERE user = '$user' ";
// see what the query really looks like
echo $q;
$res = mysql_query($q) or die(mysql_error());
if(mysql_numrows($res) == '0'){
echo 'no results';
}
else{
while ( $row = mysql_fetch_assoc($res) ) {
$userdetails = $row["notes"];
}// end sql while
}
there is or will be (one for now) multiple entires in the db it should be checking to see if the account is active or not but it seems like it’s not retrieving the information properly. I’m just trying to see if it echos out the right information 1 or 0