# PHP MySQL login script problem

**URL:** <https://forum.kirupa.com/t/php-mysql-login-script-problem/223484>\
**Category:** programming\
**Created:** [April 23, 2007, 8:24am UTC](https://forum.kirupa.com/t/php-mysql-login-script-problem/223484 "2007-04-23T08:24:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ususim](https://avatars.discourse-cdn.com/v4/letter/u/9fc348/32.png) [@ususim](https://forum.kirupa.com/u/ususim)\
**Post date:** [April 23, 2007, 8:24am UTC](https://forum.kirupa.com/t/php-mysql-login-script-problem/223484/1 "2007-04-23T08:24:19Z")

</div>

hi all,

i am new to php & mysql. i tried a tutorial at [http://www.tutorialized.com/tutorial/php-simle-login-script/9963](http://www.tutorialized.com/tutorial/php-simle-login-script/9963), modified the database information, but somehow getting an error as below

> **Warning** : mysql\_num\_rows(): supplied argument is not a valid MySQL result resource in **/hsphere/local/home/claybric/kc.claybricks.com/checklogin.php** on line **20**  
> Wrong Username or Password  
> my testing page is available at: [Untitled Document](http://www.claybricks.com/main_login.php)

code for the pages are as follow:  
main\_login.php  
\<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)”\>  
\<html xmlns=“[XHTML namespace](http://www.w3.org/1999/xhtml)”\>  
\<head\>  
\<meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1” /\>  
\<title\>Untitled Document\</title\>  
\</head\>

\<body\>  
\<table width=“300” border=“0” align=“center” cellpadding=“0” cellspacing=“1” bgcolor=“#CCCCCC”\>  
\<tr\>  
\<form name=“form1” method=“post” action=“checklogin.php”\>  
\<td\>  
\<table width=“100%” border=“0” cellpadding=“3” cellspacing=“1” bgcolor=“#FFFFFF”\>  
\<tr\>  
\<td colspan=“3”\>\<strong\>Member Login \</strong\>\</td\>  
\</tr\>  
\<tr\>  
\<td width=“78”\>Username\</td\>  
\<td width=“6”\>:\</td\>  
\<td width=“294”\>\<input name=“myusername” type=“text” id=“myusername”\>\</td\>  
\</tr\>  
\<tr\>  
\<td\>Password\</td\>  
\<td\>:\</td\>  
\<td\>\<input name=“mypassword” type=“password” id=“mypassword”\>\</td\>  
\</tr\>  
\<tr\>  
\<td\>&nbsp;\</td\>  
\<td\>&nbsp;\</td\>  
\<td\>\<input type=“submit” name=“Submit” value=“Login”\>\</td\>  
\</tr\>  
\</table\>  
\</td\>  
\</form\>  
\</tr\>  
\</table\>  
\</body\>  
\</html\>

checklogin.php  
\<?php  
$host=‘SECRET’; // Host name  
$username=‘SECRET’; // Mysql username  
$password=‘SECRET’; // Mysql password  
$db\_name=‘SECRET’; // Database name  
$tbl\_name=‘SECRET’; // Table name

// Connect to server and select databse.  
mysql\_connect(“$host”, “$username”, “$password”)or die(“cannot connect”);  
mysql\_select\_db(“$db\_name”)or die(“cannot select DB”);

// username and password sent from signup form  
$myusername=$\_POST[‘myusername’];  
$mypassword=$\_POST[‘mypassword’];

$sql=“SELECT \* FROM $tbl\_name WHERE username=‘$myusername’ and password=‘$mypassword’”;  
$result=mysql\_query($sql);

// Mysql\_num\_row is counting table row  
$count=mysql\_num\_rows($result);  
// If result matched $myusername and $mypassword, table row must be 1 row  
if($count==1){  
// Register $myusername, $mypassword and redirect to file “login\_success.php”  
session\_register(“myusername”);  
session\_register(“mypassword”);  
header(“location:login\_success.php”);  
}  
else {  
echo “Wrong Username or Password”;  
}  
?\>

and finally, login\_success.php  
\<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)”\>  
\<?  
session\_start();  
if(!session\_is\_registered(myusername)){  
header(“location:main\_login.php”);  
}  
?\>

\<html\>\<title\>Login\_success\</title\>  
\<body\>  
Login Successfully  
\</body\>  
\</html\>

i’ll really appreciate your help. thanks in advance
