Find the problem in this code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
umapathy
Forum Newbie
Posts: 14
Joined: Fri Jul 28, 2006 2:21 am
Location: chennai - india

Find the problem in this code

Post by umapathy »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Dear All,

I have the following code,if i run this program the error is " Unable to excute the query:"
Can any one fix the problem


code :

Code: Select all

<?
session_start();
	$msg_pass="india";
	$msg_user="umapathy	";
	error_reporting(e_all);
	//include("dbconnect.php");
	if($_POST['login'])
	$username=trim($_POST['username']);
	$password=trim($_POST['password']);
	echo $username;
	echo $password;
	if($username && $password)
	{
		//include database		
		$con1=mysql_connect("********","****","****");
		mysql_select_db("****",$con1);
		$sql="SELECT * FROM member WHERE username='".$username."'";
		$result=mysql_query($sql,$con1) or die() ;
		//echo $result;
		if($result)
			$count=mysql_num_rows($resulr);
			if($count>0)
			{
				$data=mysql_fetch_assoc($result);
				if($data["password"]==$password)
				{
					$_SESSION["user"]=$username;
					echo "true";
				}
				else
				{
					$msg_pass="Wrong Password,Please Try again";
				}
			}
			if($user==$username && $pass ==$password and $username !=NULL)
			{
				if($disable=='Yes')
				{
					echo "Your account has been disabled";
					exit;
				}
			}
		}
		else
		{
			echo "Unable to excute the query:".mysql_errno($con);
		}
###########################################
			?>
			<fieldset>
			<legend>Please Login</legend>
			<form name="login" method="post" action="<?echo $PHP_SELF ?>">
			<?
				echo ($msg_user)?"<br/>".$msg_user."<br/>":"";
			?>
			Username:<input type="text" name="username" maxlength="120"/><br/>
			<?
				echo($msg_pass)?"<br/>".$msg_pass."<br/>":"";
			?>
			Password:<input type="password" name="password" maxlength="120" /><br/>
			<input type="submit" name="login" value="login"/>
			</form></fieldset>
Everah | Removed DB connection details. PLEASE DO NOT INCLUDE YOUR ACTUAL CONNECTION DETAILS.

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

The conditional statement

Code: Select all

if ($result)
is evaluating to false. Try running this query (with an actual username) in your DB utility (like phpMyAdmin) and see if it returns any results. You may also want to echo the query before it executes to see what the DB is seeing.

Code: Select all

SELECT * FROM member WHERE username='<USE_A_REAL_USERNAME>';
Post Reply