SUNIL16 Posted January 11, 2010 Share Posted January 11, 2010 Hi Friends, I am getting below error Warning: mysql_query() expects parameter 1 to be string, resource given in C:\xampp\htdocs\lib_management\login.php on line 22 Wen i run this code <?php require("config.php"); if(isset($_REQUEST["login_clicked"])) { if($_REQUEST["username"]=="") { header("location:login.php?msg=please enter a valid username"); exit(); } elseif($_REQUEST["password"]=="") { header("location:login.php?msg=please enter a valid password"); exit(); } else { $password=$_REQUEST["password"]; $username=$_REQUEST["username"]; } $sql=mysql_query("SELECT username,password FROM admintable WHERE username='$_POST[username]' AND password='$_POST[password]'"); $result = mysql_query($sql) or die (mysql_error()); $num = mysql_num_rows($result); if ( $num != 0 ) { header("location:home.html"); exit(); } else { header("location:login.php?msg=invalid login"); } } ?> My table code is <?php require "config.php"; $result = mysql_query("CREATE TABLE `admintable` ( `admintableid` int(20) NOT NULL auto_increment, `username` varchar(200) collate latin1_general_ci NOT NULL default '', `password` varchar(200) collate latin1_general_ci NOT NULL default '', PRIMARY KEY (`admintableid`) )"); if (!$result) { die('Invalid query: ' . mysql_error()); } ?> What is the above warning i am not getting. Link to comment https://forums.phpfreaks.com/topic/188027-what-is-the-error/ Share on other sites More sharing options...
Mchl Posted January 11, 2010 Share Posted January 11, 2010 Change $sql=mysql_query("SELECT username,password FROM admintable WHERE username='$_POST[username]' AND password='$_POST[password]'"); to $sql="SELECT username,password FROM admintable WHERE username='$_POST[username]' AND password='$_POST[password]'"; Link to comment https://forums.phpfreaks.com/topic/188027-what-is-the-error/#findComment-992666 Share on other sites More sharing options...
SUNIL16 Posted January 11, 2010 Author Share Posted January 11, 2010 Is my sql syntax wrong! It worked for me in live server? Suggestions... Link to comment https://forums.phpfreaks.com/topic/188027-what-is-the-error/#findComment-992796 Share on other sites More sharing options...
KevinM1 Posted January 11, 2010 Share Posted January 11, 2010 Is my sql syntax wrong! It worked for me in live server? Suggestions... Yes, your syntax is wrong. Mchl gave you the solution. Link to comment https://forums.phpfreaks.com/topic/188027-what-is-the-error/#findComment-992800 Share on other sites More sharing options...
Mchl Posted January 11, 2010 Share Posted January 11, 2010 Although admittedly SQL is all right (not considering possible SQL injection). PHP is wrong however and there is no way it was working anywhere. Link to comment https://forums.phpfreaks.com/topic/188027-what-is-the-error/#findComment-992823 Share on other sites More sharing options...
SUNIL16 Posted January 12, 2010 Author Share Posted January 12, 2010 Ya thanks i agree i was wrong. i send query two times. Link to comment https://forums.phpfreaks.com/topic/188027-what-is-the-error/#findComment-993341 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.