michaelkane Posted November 14, 2009 Share Posted November 14, 2009 Hi guys how are you doing, I am unable to execute very basic php script connecting with mysql. being a noob I just need a quick fix thats all.. here is the code: <?php session_start(); ?> <html> <body> <form action='index.php?login=yes' method=POST> Username: <input type=text name='user'><br/> Password: <input type=password name='pass'><br/> <input type=submit value='SignIn!'> </form> <?php $user=$_POST['user']; $pass=$_POST['pass']; $login=$_GET['login']; if($login=='yes'){ $con=mysql_connect('localhost','root',''); mysql_select_db('test'); $get=mysql_query("SELECT count(id) FROM database WHERE user='$user' and pass='$pass'"); $result=mysql_result($get,0); mysql_close($con); if($result!=1) echo "Login failure"; else{ echo "Login success !"; $_SESSION['user']=$user; }; }; ?> <body> </html> error I am getting is: Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\roooooot\xampp\htdocs\index.php on line 22 Login failure 1. I am assuming root and '' pass is to login mysql. 2. test is the database 3. 'database' is the table where it is checking user/pass the rest is straightforward. can anyone explain what could be wrong. getting same error with a nonexisting database. Thank you! Link to comment https://forums.phpfreaks.com/topic/181487-help-with-mysql-php-with-basic-username-authentication/ Share on other sites More sharing options...
felixtgomezjr Posted November 18, 2009 Share Posted November 18, 2009 In your line: $result=mysql_result($get,0); You lack one parameter and that is the column/field name. You should have $result=mysql_result($get,0,fieldname_here); But looking deeper in your code, your sql is wrong because you did not put an alias to your count(id). You should have like this $get=mysql_query("SELECT count(id) as howmany FROM database WHERE user='$user' and pass='$pass'"); $result=mysql_result($get,0,"howmany"); I hope that helps. Link to comment https://forums.phpfreaks.com/topic/181487-help-with-mysql-php-with-basic-username-authentication/#findComment-959812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.