Jump to content


Photo

SQL query not working in PHP


  • Please log in to reply
3 replies to this topic

#1 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 15 July 2006 - 08:04 PM

<?php
	setcookie("user","",0,"/","www.usnet1.net",0);
?>
<html>
<head>
<title>Log-in</title>
</head>

<body bgcolor="default">
<?php
	$cn=@mysql_connect("localhost","username","password") or die(mysql_error());
	@mysql_select_db("database name",$cn);
	$sql="SELECT password FROM $_POST[username]";
	$result=@mysql_query($sql,$cn) or die(mysql_error());
	if($result!=$_POST[password])
	{
		echo $result;
		die("Incorrect password!");
	}
	else
	{
		$_COOKIE[user]=$_POST[username];
		echo "Welcome";
		echo "<a href=\"panel.php\">Control panel</a>";
	}
?>

</body>
</html>

When i run this script it gives: Resource id #2Incorrect password!
what's wrong?



Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

#2 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 15 July 2006 - 08:05 PM

as it says in the manual, mysql_query() returns a resource ID for the results of the query.  in order to extract the results, you need to use a grabbing function such as mysql_fetch_row(), mysql_fetch_array(), or mysql_result().

#3 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 15 July 2006 - 08:06 PM

Thanks

Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 15 July 2006 - 10:22 PM

$sql="SELECT password FROM $_POST[username]";


Do you really have table for each user, each table having a record containing the password?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users