Error:
index.phpWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in H:\wamp\www\randomn\index.php on line 32
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in H:\wamp\www\randomn\index.php on line 33
config.php (table is commented out because I've already added it)PHP Code:<?php
session_start();
include("config.php");
if ($_GET['login'])
{
switch ($_GET['login'])
{
case '1':
echo("Welcome to something not worth the warm welcome.
<form action='?login=2' method='post'>
<strong>Username</strong>: <input type='text' name='username' size='20' />
<br /><br />
<strong>Password</strong>: <input type='text' name='password' size='20' />");
break;
case '2':
$username = $_POST['username'];
$password = $_POST['password'];
$password = md5($password);
if ($username == "" || $password == "")
{
die("You did not enter a username and/or password.");
}
list($user) = mysql_fetch_array(mysql_query("SELECT `username` FROM `staff` WHERE username='$username'"));
list($pass) = mysql_fetch_array(mysql_query("SELECT `password` FROM `staff` WHERE password='$password'"));
if ($username == "$user" && $password == "$pass")
{
$sql = mysql_query("SELECT * FROM `staff` WHERE username='$user' AND password='$pass'");
if (mysql_num_rows($sql) != 1)
{
die("Error...");
}
$result = mysql_fetch_array($sql);
$_SESSION['user'] = $result['username'];
$_SESSION['level'] = $result['level'];
$_SESSION['ip'] = $_SERVER['REMOT_ADDR'];
header("location: home.php");
}
break;
}
}
else if (!$_GET['login'])
{
header("location: ?login=1");
}
else
{
die("Error.");
}
?>
Any ideas why its giving me this error? I'm testing on localhost, wampserver.PHP Code:<?php
$host = "localhost";
$user = "root";
$pass = "";
$data = "hab";
$connect = mysql_connect($host, $user, $pass);
if (!$connect)
{
echo("Error connecting to database.");
}
mysql_select_db($data);
/*
mysql_query("CREATE TABLE `users` (
`id` int(255) NOT NULL auto_increment,
`username` varchar(500) collate latin1_general_ci NOT NULL,
`password` varchar(500) collate latin1_general_ci NOT NULL,
`level` varchar(500) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=44 ;
") or exit("Couldn't create users table.");
echo("Users table created."); */
?>





Reply With Quote
