Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

mysqli parameters problem - admin login page

Featured Replies

Hi there, I've got a database set up and it connects just fine, but when trying to log into the admin area I was getting about 10 errors, now I've cut it down to the final two but I can't figure it out. So any help would be greatly appriciated!! :)

Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/content/12/11792312/html/myshop/storeadmin/admin_login.php on line 17

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home/content/12/11792312/html/myshop/storeadmin/admin_login.php on line 19

 

and here is the admin login page:

 

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

<?php
if(isset($_POST["username"])&& isset($_POST["password"])){
	
$manager = preg_replace('#[^A_Za-z0-9]#i', ',' , $_POST["manager"]);
$password = preg_replace('#[^A_Za-z0-9]#i', ',' , $_POST["password"]);

include"../storescripts/connect_to_mysql.php";

$sql = mysqli_query("SELECT * FROM admin WHERE username='$manager' AND password='$password' LIMIT 1");

$existCount = mysqli_num_rows($sql);
if($existCount == 1) {
		while($row = mysqli_fetch_array($sql)){
			$id = $row["id"];
		}
		$_SESSION["id"] = $id;
		$_SESSION["manager"] = $manager;
		$_SESSION["password"] = $password;
		header("location:../index.php");
		exit();
		}
		else 
		{
		echo'UberPass Failed - <a href="index.php">Click here</a>';
		exit();
		}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin Homepage</title>
<link href="../style.css" rel="stylesheet" type="text/css" />
</head>

<body>

    <div id="mainwrapper">  
		<?php include_once("../template_header.php");?> 
            <div id="maincon">
            
            <form id="form1" name="form1" method="post" action="http://www.uberdelic.com/myshop/storeadmin/admin_login.php">
                <p>Username:
                    <input name="username" type="text" id="username" size="40"/>
                </p>
                
                <p>Password:
                    <input name="password" type="password" id="password" size="40"/>
                </p>
                
                <p>
                    <input type="submit" name="button" id="button" value="Log In"/>
                </p>
            </form>
            
            </div>
		<?php include_once("../template_footer.php");?> 
    </div>

</body>
</html>

 

$link = mysqli_connect($server, $username, $password, $db_name);

$sql = mysqli_query($link, "SELECT * FROM admin WHERE username='$manager' AND password='$password' LIMIT 1");

 

notice the $link needs to connect...

so needs to follow something like this mysqli_query ( mysqli link, string query [, int resultmode] )

 

and where you have username='$manager' should it not be "$_POST["username"]" so that the check can be made? not sure how you have done the logic but your way might be correct!

 

hope that helps.

The DB connection is clearly fine or there would be a Failed to connect to database error.

 

Changing line 12 from:

$manager = preg_replace('#[^A_Za-z0-9]#i', ',' , $_POST["manager"]);

to:

 

$manager = preg_replace('#[^A_Za-z0-9]#i', ',' , $_POST["username"]);

should fix it.

 

However it is always better to keep the names of your variables consistent through the script wherever possible it makes debugging and editing a lot easier.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.