Problem with if ($result || mysql_num_rows($result) == 0)

Hello everyone.

I am having trouble with a UCP for a game server of mine.
It seems that mysql_num_rows does not work on my localhost or webhosting.
Unless there is something wrong with my script…

[code]<?php
if (!isset($_POST[‘username’]))
{
require_once(“includes/header.php”);
?>




User Control Panel - Login




<?php
if (isset($_SESSION[“errno”]))
$errno = $_SESSION[“errno”];
else
$errno = 0;
								if (isset($_SESSION["loggedout"]))
									$_SESSION["loggedout"] = true;
								else
									$_SESSION["loggedout"] = false;
									
								if ($errno==2)
									echo "<span style='text-align:left;'><p>The UCP is currently unavailable! [Error #2]</p></span>";
								elseif ($errno==3)
									echo "<span style='text-align:left;'><p>Invalid Username / Password! [Error #3]</p><p>Please login using your xUltimate Roleplay account details to continue.</p></span>";
								elseif ($errno==4)
									echo "<span style='text-align:left;'><p>You have used up your 3 login attempts. You are now locked out for 15 minutes.[Error #4]</p></span>";
								elseif ($errno==5)
									echo "<span style='text-align:left;'><p>Your username and new password has been emailed to you.[Error #5]</p></span>";
								elseif ($errno==6)
									echo "<span style='text-align:left;'><p>Invalid Username / Password!</p><p>Please login using your xUltimate Roleplay account details to continue.[Error #6]</p></span>";	
								elseif ($errno==7)
									echo "<span style='text-align:left;'><p>Your account has been created successfully. Please login here.[Error #7]</p></span>";	
								elseif ($_SESSION["loggedout"]==true)
									echo "<span style='text-align:left;'><p>You are now logged out.</p><p>Please login using your xUltimate Roleplay account details to continue.[Error #7]</p></span>";
								else
									echo "<span style='text-align:left;'><p>Please login using your xUltimate Roleplay account details to continue.</p></span>";
									
								unset($_SESSION["errno"]);
								unset($_SESSION["loggedout"]);

?>










Username:
Password:
								<br />
								<p><a href="#">Forgot your password?</a><strong> | </strong><a href="#">Want to register?</a></p>
								<input type="submit" value="Login"/>
							</form>
						</div>
					</div>
				</div>
			</div>
<?php require_once("includes/footer.php"); } else { // login attempt if (!isset($_POST['username']) or !isset($_POST['password'])) { $_SESSION['errno'] = 6; header("Location: /ucp/login/"); } else { $MySQLConn = @mysql_connect($Config['database']['hostname'], $Config['database']['username'], $Config['database']['password']); if (!$MySQLConn) { $_SESSION['errno'] = 2; header("Location: /ucp/login/"); } $selectdb = @mysql_select_db($Config['database']['database'], $MySQLConn); $username = mysql_real_escape_string($_POST['username'], $MySQLConn); $password = md5($Config['server']['hashkey'] . $_POST['password']); $result = mysql_query("SELECT `id`,`admin` FROM `accounts` WHERE `username`='" . $username . "' AND `password`='" . $password . "' LIMIT 1", $MySQLConn); if (!$result || mysql_num_rows($result) == 0) { $_SESSION['errno'] = 3; header("Location: /ucp/login/"); } else { $row = mysql_fetch_assoc($result); $_SESSION['ucp_loggedin'] = true; $_SESSION['ucp_username'] = $username; $_SESSION['ucp_userid'] = $row['id']; $_SESSION['ucp_adminlevel'] = $row['admin']; header("Location: /ucp/main/"); } } } ?>[/code]

The problem occurs here

if (!$result || mysql_num_rows($result) == 0) { $_SESSION['errno'] = 3; header("Location: /ucp/login/"); }
Any help is appreciated.

this is redundant :

[php]if (!$result || mysql_num_rows($result) == 0)[/php]

change it to :

[php]if (mysql_num_rows($result) == 0)[/php]

or

[php]if (!mysql_num_rows($result) )[/php]

Still receiving the same error.

well what is the exact error that you are getting?

It’s the error for my UCP where it uses the errno = 3; it’s giving me “Invalid Username/Password”

you need to do some debugging change:
[php]$result = mysql_query(“SELECT id,admin FROM accounts WHERE username=’” . $username . “’ AND password=’” . $password . “’ LIMIT 1”, $MySQLConn);
[/php]

to
[php]$result = mysql_query(“SELECT id,admin FROM accounts WHERE username=’” . $username . “’ AND password=’” . $password . “’ LIMIT 1”, $MySQLConn)or die(mysql_error());[/php]
lets make sure there is no error that comes from that.
also just before that have it echo the username and password and verify that they match with the database, so go to the actual database through phpmyadmin and and see the values. make sure password is md5’d in the database.

The password and username are fine in the database as they were setup through my server.
When I do the debugging the UCP stops working and when I tell it to echo the username and password it doesn’t.

Sponsor our Newsletter | Privacy Policy | Terms of Service