- Code: Select all
<form action="login.php" method ="post" onsubmit="return validate (this);"> <div style="clear:both; font-family:Verdana, Geneva, sans-serif; font-size:10px; color:#333;">Username</div>
<input name="username" type="text" id="name" style="width:300px; border:1px; border-style:solid; border-color:#969696; height:20px; margin-bottom:8px; clear:left;" />
<div style="clear:both; font-family:Verdana, arial; font-size:10px; color:#333;"> Password </div>
<input name="password" type="password" id="password" style="width:300px; border:1px; border-style:solid; border-color:#969696; height:20px; margin-bottom:8px; clear:left;"/>
<div style="margin-bottom:8px; clear:both; width:300px; font-family:Verdana, Geneva, sans-serif; font-size:10px; color:#333; text-align:right;"><span style="clear:both; font-family:Verdana, Geneva, sans-serif; font-size:10px; color:#333;"></span><span><input type="submit" name="submit" value="LOG IN" style="background-color:#090; color:#FFF; border:none; cursor:pointer" /> </span></div>
</form><br />
and here is my login.php code
- Code: Select all
<?php
$host="localhost";
$username="root";
$password="";
$db_name="transportdb";
$con=mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
//echo "connected <br/>";
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM user WHERE LoginName='$myusername' and Password='$mypassword'";
//echo "$sql <br/>";
$result=mysql_query($sql,$con) or die ('Unable to run query:'.mysql_error());
$count=mysql_num_rows($result);
if($count==1){
session_register("myusername");
session_register("mypassword");
header("location:home.php");
}
else {
echo "Wrong Username or Password";
}
?>
here is the error i am getting
Unable to run query:Table 'transportdb.user' doesn't exist
I am stuck with this because //echo "connected <br/>"; and //echo "$sql <br/>"; successfully executed but i think i have problem in section
$result=mysql_query($sql,$con) or die ('Unable to run query:'.mysql_error());
$count=mysql_num_rows($result);
if($count==1){
session_register("myusername");
session_register("mypassword");
header("location:home.php");
}
else {
echo "Wrong Username or Password";
}
?>


