Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.