0

Hello Dani web. This is my first post here so please bear with me if its not 100% correctly setup.

Anyways I'm a rookie to php and mysql and I've run into problem with my final project in my first php class.

The error given is: "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\lokaverkefni\signing.php on line 18"

All databases in mysql are correct.

Anyways to share the php code, heres the following.

sign_in.php

<?php
if (isset($_COOKIE['member'])) {
include "admin_login.php";

}
else 
{
include "signing.php";
}
?>

signing.php

<?php
$hostUrl = 'localhost';
$userName = 'root';

$connectID = mysql_connect($hostUrl, $userName)
  or die ("Sorry, can't connect to database");

mysql_select_db("frettir", $connectID)
  or die ("Unable to select database");

?>
<?php
if (@$_POST['submitted']) {
	$username = @$_POST['username'];
	$password = @$_POST['password'];
	
$result = mysql_query("SELECT Username FROM login_tbl WHERE username='".$username."' and password='".$password."'", $connectID); 
	if(mysql_num_rows($result) == 1)
	{
		setcookie ("member", time(), time()+15);	
		echo "Success";
	}
	else {
	echo "<p style='color:red;'>Rangt Lykilorð eða username</p>";	
	}
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="styles.css" type="text/css" />
<title>Administrator Panel</title>
</head>

<body>
<div id="container">
	<div id="header">
<?php 
 include "_includes/header.php";
?>
	</div>
	<div id="nav">
<?php 
 include "_includes/menu.php";
?>
	</div>
		<div id="page">
        	<div id="content">
<form action="<?php $connectID['PHP_SELF'] ?>" method="post">
	<label for="username">Username</label> <br/>
	<input type="text" size="20" name="username" /></br>
		<label for="password">Password</label> <br/>
	<input type="password" size="20" name="password" /></br>
	
	<input type="submit" value=" Log In" name="submitted"/>
	</form>
    <br />
</div>
<div class="clear"></div>
</div>
<div id="footer">
<?php 
 include "_includes/footer.php";
?>
</div>
</div>
</body>
</html>

The ones below here I am not sure if they are required but I will make them follow aswell.

admin_login.php

<?php
$hostUrl = 'localhost';
$userName = 'root';

$connectID = mysql_connect($hostUrl, $userName)
  or die ("Sorry, can't connect to database");

mysql_select_db("frettir", $connectID)
  or die ("Unable to select database");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Administrator Panel</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
</head>
<body>
<div id="container">
	<div id="header">
    
<?php 
 include "_includes/header.php";
?>
	</div>
	<div id="nav">
<?php 
 include "_includes/menu.php";
?>
	</div>
	<div id="content">
		<div id="page">
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<h3>Skrá Frétt</h3>
<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">

<!--topic_name-->
<label for="topic_name"	>Fyrirsögn</label><br />
<input name="topic_name" type="text" size="30" id="topic_name" />
<!--topic_description-->
<br />
<br />
<label for="topic_description">Meginmál</label><br />
<textarea name="topic_description" id="topic_description" rows="20" cols="80"></textarea><br /><br />
<input type="submit" value=" Skrá inn frétt " name="submitted" />
<br /> <br />
</form>
</form>
        <?php
$myResult = mysql_query("SELECT * from frett", $connectID);

print '<table>'."\n";
while ($row = mysql_fetch_array($myResult, MYSQL_ASSOC)) {

   print '<tr>'."\n";
	 print '<td><h3>'.$row['titill'].'</h3></td>'."\n";
	 print '</tr>'."\n";
	 print '<tr>'."\n";
	 $id=$row['id'];
	 print '<td class="description">'.$row['frett'].'<br /><br />#'.$row['id'].'</td>'."\n";
	 print '</tr>'."\n";
}

print '</table>'."\n";
?>
</div>
<div class="clear"></div>
</div>
<div id="footer">
<?php 
 include "_includes/footer.php";
?>
</div>
</div>
</body>
</html>

index.php

<?php
$hostUrl = 'localhost';
$userName = 'root';
// connect to database
$connectID = mysql_connect($hostUrl, $userName)
  or die ("Sorry, can't connect to database");

//select the database to read from
mysql_select_db("frettir", $connectID)
  or die ("Unable to select database");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Deadmau5</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
</head>
<body>
<div id="container">
	<div id="header">
<?php 
 include "_includes/header.php";
?>
	</div>
	<div id="nav">
<?php 
 include "_includes/menu.php";
?>
	</div>
	<div id="content">
		<div id="page">
        <?php
$myResult = mysql_query("SELECT * from frett", $connectID);

print '<table>'."\n";
while ($row = mysql_fetch_array($myResult, MYSQL_ASSOC)) {

   print '<tr>'."\n";
	 print '<td><h3>'.$row['titill'].'</h3></td>'."\n";
	 print '</tr>'."\n";
	 print '<tr>'."\n";
	 $id=$row['id'];
	 print '<td class="description">'.$row['frett'].'<br /><br />#'.$row['id'].'</td>'."\n";
	 print '</tr>'."\n";
}

print '</table>'."\n";
?>
</div>
<div class="clear"></div>
</div>
<div id="footer">
<?php 
 include "_includes/footer.php";
?>
</div>
</div>
</body>
</html>

I appreciate any help and please don't answer with to complicated replies. I'm only a rookie and as you can see this is all I could achieve.

8
Contributors
8
Replies
36
Views
6 Years
Discussion Span
Last Post by diafol
0

Hi

Add a condition before line 18 in signing.php as given below

if(is_resource($result))
{
if(mysql_num_rows($result) == 1)
{
setcookie ("member", time(), time()+15);
echo "Success";
}

else {
echo "<p style='color:red;'>Rangt Lykilorð eða username</p>";
}
}
0

Your SQL statment is failing so the mysql_query is returning a boolean value (false) instead of a result set.

Make sure that your SQL statement is valid.

1

Try 'U' in small case.

echo $sql = "SELECT [B]u[/B]sername FROM login_tbl WHERE username='".$username."' and password='".$password."'";
$result = mysql_query($sql, $connectID);

If it still not works then run echoed query in phpmyadmin.

0

How about Warning: mysql_num_rows() expects parameter 1 to be resource, ?
I am so confused!. Help me please?

0

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/zidarir/public_html/register.php on line 16
ï؟½ï؟½ï؟½ ï؟½ï؟½ï؟½ ï؟½ï؟½ ï؟½ï؟½ï؟½ï؟½ï؟½ï؟½ ï؟½ï؟½ï؟½ï؟½ï؟½ ï؟½ï؟½
Help me please?

Edited by ILIYYA

0

If you can't be bothered to post your code or not resurrect a 5 year old thread, then you are doomed - doubly so if you're messing around with deprecated code :(

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.