Does Anyone Know why PHP is Throwing This Error?

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
ultraMLG1108
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Mar 27, 2017 9:17 am

Mon Mar 27, 2017 9:24 am

Hello!

I'm not quite sure why PHP is throwing the error

Code: Select all

Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\home.php on line 24
on my login form. Here is the code for my login form:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
<link rel="stylesheet" href="/dashboard/stylesheets/all.css" type="text/css" />
</head>
<body>
<div id="main">
<?php
if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
{
	
	?>
	<h1>Member Area</h1>
	<p>Thanks for logging in! You are <code><?=$_SESSION['Username']?></code> and your email address is <code><?=_SESSION['EmailAddress']?></code>.</p>
	
	<?php
	
}
elseif(!empty($_POST['username']) && !empty($_POST['password']))
{
	
	$usernameFromPost = mysqli_real_escape_string($_POST['username']);
	$passwordFromPost = $_POST['password'];
        $hashedPasswordFromDB = 'hashedpasswordplaceholder';
	
	if (password_verify($passwordFromPost, $hashedPasswordFromDB)) {
		?>
		<h1>Welcome to the Members Only Area!!</h1>
		
		
		
		<?php
	} else {
		?>
		
		<h1>Sorry, your password could not be verified.</h1>
		
		<?php
	}
	
} else {
	?>
	<h1>Please Login</h1>
	
	<form method="post" action="home.php" name="loginform" id="loginform">
	<fieldset>
		<label for="username">Username:</label><input type="text" name="username" id="username" /><br />
		<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
		<input type="submit" name="login" id="login" value="login" />
	</fieldset>
	</form>
	
	
	
	
	
	
	
	<?php
}




	
	
	




?>
</body>
</html>
I'm new to mysqli. Thanks in advance!
AdoptiveSolution
php-forum Super User
php-forum Super User
Posts: 167
Joined: Wed Jun 15, 2016 8:35 am

Mon Mar 27, 2017 9:47 am

You didn't make a connection to the database :

http://php.net/manual/en/mysqli.real-escape-string.php
I'm new to mysqli
That's why they invented manuals.
Post Reply