Jump to content

What is the error?


SUNIL16

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.