Ok I have included the code you suggested to echo the query,
Now the error has chagned to
SELECT uname FROM gallery_users WHERE uname='tom' AND pass='test1'Unable to execute the query : from here You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #4' at line 1
The updated version of the code I am currentlty working with is:
PHP Code:
<?php
session_start();
ini_set('display_errors', 1);
error_reporting(E_ALL);
$msg_pass="";
$msg_user="";
$username=trim($_POST['username']);
$password=trim($_POST['password']);
if($username && $password)
{
// connect to database
include("includes/db_con1.php");
// check if the username exists
$cQuery = mysql_query("SELECT uname FROM gallery_users WHERE uname='$username' AND pass='$password'");
echo $sql = "SELECT uname FROM gallery_users WHERE uname='$username' AND pass='$password'";
$cQuery = mysql_query($sql) or die(mysql_error());
$rs=mysql_query($cQuery);
if($rs)
{
$count=mysql_num_rows($rs);
if($count>0)
{
//read the data from table
$data=mysql_fetch_assoc($rs);
if(strcmp($data['password'],$ushapass))
{
// setting a session with a variable named valid user which stores the username
$_SESSION['validuser']=$username;
}
else
{
$msg_pass= "Please check your username and password are correct";
}
}
else
{
$msg_user="Please check your username and password are correct";
}
}
else
{
echo "Unable to execute the query : from here ".mysql_error($con);
}
}// end of check
if(isset($_SESSION['validuser']))
{
echo " You are Logged in as : ".$_SESSION['validuser']."<br /><br />";
echo "you will be transfered to your admin page in 5 seconds.";
$validuser=TRUE;
?>
<meta http-equiv="Refresh" content="3; URL=adminindex.php">
<?php
}
else
{
?>
<form method="post" action="<?php echo $PHP_SELF ?>">
<fieldset>
<legend>Login</legend>
<?php
echo ($msg_user)?"<br />".$msg_user."<br />":"";
?>
<label>Username:
<input type="text" name="username" value="" size="25"/>
</label><br/>
<?php
echo ($msg_pass)?"<br />".$msg_pass."<br />":"";
?>
<label>Password:
<input type="password" name="password" value="" size="25"/>
</label><br/>
<input type="submit" name="submit" value="Login">
</fieldset>
</form>
<?php
}
?>
Bookmarks