Skip navigation links

MySQL Forums :: PHP :: Admin login script not working


Advanced Search

Admin login script not working
Posted by: Nick Roy ()
Date: March 01, 2011 10:59AM

I am working on a content management system. I cannot get my admin login area to work. It is supposed to check the mysql database table called "admin." I have four fields in the admin table as follows: id, username, password, last_log_date.

When I test out the script on the server, I get the following error messages:

Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/peterter/public_html/admin/admin_check.php on line 9

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home/peterter/public_html/admin/admin_check.php on line 11
That information is incorrect, try again Click Here

My Php blog on the admin_check.php page is as follows:

<?php
// Written by Nick J Roy, Galt Mile Media on February 1, 2011
session_start();
if (isset($_SESSION["username"])) {
header("location: index.php");
exit();
}
?>

<?php
// Parse the log in form if the user has filled it out and pressed "Log In"
if (isset($_POST["username"]) && isset($_POST["password"])) {

$username = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["username"]); // filter everything but numbers and letters
$password = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["password"]); // filter everything but numbers and letters
// Connect to the MySQL database
include "../sitescripts/connect_to_mysql.php";
$sqlCommand = mysqli_query("SELECT id FROM admin WHERE username='$username' AND password='$password' "); // query the person
// ------- MAKE SURE PERSON EXISTS IN DATABASE ---------
$existCount = mysqli_num_rows($sqlCommand); // count the row nums
if ($existCount == 1) { // evaluate the count
while($row = mysqli_fetch_array($sqlCommand)){
$id = $row["id"];
}
$_SESSION["id"] = $id;
$_SESSION["username"] = $username;
$_SESSION["password"] = $password;
header("location: index.php");
exit();
} else {
echo 'That information is incorrect, try again <a href="index.php">Click Here</a>';
exit();
}
}
?>

My php block on the index.php of the admin area is as follows:

<?php
session_start();
if(!isset($_SESSION["username"]))
{
header("location: admin_check.php");
exit();
}
?>

What am i doing wrong here?

Thanks

Options: ReplyQuote


Subject Written By Posted
Admin login script not working Nick Roy 03/01/2011 10:59AM
Re: Admin login script not working Barry Galbraith 03/01/2011 02:43PM
Re: Admin login script not working Nick Roy 03/01/2011 03:35PM
Re: Admin login script not working Barry Galbraith 03/01/2011 05:15PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.