Jump to content

mysql_num_rows() will not work...


Neptunus Maris

Recommended Posts

mysql_num_rows() function and mysql_fetch_array() will not work what so ever

 

my code: (pretty simple) it will just turn out a blank screen.

 

if (!isset($_POST[submit])) {
$show_form = "yes";
} elseif (isset($_POST[submit])) {
$pwd = md5($_POST[password]);
$query =  "SELECT * FROM admins WHERE f_name = '$_POST[f_name]' AND l_name = '$_POST[l_name]' AND password = '$pwd'";
$result = mysql_query($query) or die(mysql_error());
$check_row = mysql_num_rows($result) or die(mysql_error());
if ($check_row != 1) {
	$error = "This Administration record is not found.  And/Or name and password do not match.";
	$show_form = "yes";
} else {
	$row = mysql_fetch_array($result) or die(mysql_error());
	if ($row[auth_lvl] == "SA") {
		$cookie = $row[adminID];
		setcookie("sa", $cookie, time()+1800, "/", 0);
		$display = "You are logged in <a href = 'control_panel.php'>Go to Control Panel</a>.";
	} else {
		$cookie = $row[adminID];
		setcookie("admin", $cookie, time()+1800, "/", 0);
		$display = "You are logged in <a href = 'control_panel.php'>Go to Control Panel</a>.";
	}
}
} //end if

 

its a script that uses $_SERVER[php_SELF]  but that is not the problem...ive tried the tow mysql functions in other types of code and it will just not work.

Link to comment
https://forums.phpfreaks.com/topic/40094-mysql_num_rows-will-not-work/
Share on other sites

Actually, best is $_POST['f_name'].  Although it works without quotes, it's risky as your variable names may clash with defined values.  And single quotes are slightly faster than double quotes.

 

But that's not causing your error.  Try changing your num_rows() line to this:

 

$check_row = mysql_num_rows($result);

 

Adding the "or die" to mysql_num_rows() doesn't work, and in fact makes things worse.  You should keep the "or die" on the other mysql calls.

 

If you still get a blank page, add ini_set('display_errors', true); at the top of your code (I am not 100% sure that is right, but the goal is to turn on display of errors)

Actually, best is $_POST['f_name'].  Although it works without quotes, it's risky as your variable names may clash with defined values.  And single quotes are slightly faster than double quotes.

 

But that's not causing your error.  Try changing your num_rows() line to this:

 

$check_row = mysql_num_rows($result);

 

Adding the "or die" to mysql_num_rows() doesn't work, and in fact makes things worse.  You should keep the "or die" on the other mysql calls.

 

If you still get a blank page, add ini_set('display_errors', true); at the top of your code (I am not 100% sure that is right, but the goal is to turn on display of errors)

 

ok thanks...very much

Archived

This topic is now archived and is closed to further replies.

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