This question already has an answer here:
Hey guys I have been working on a social networking site and have been working on the login and registration systems. I am pretty new to php so my code may not be the best. The issue I am having right now is my login. This is my log in form on my index.php page.
<form name="loginform" method="post" action="includes/login.php" >
<table>
<input type="submit" id="submitbox" name="login" value="Submit">
<input type="password" name="password" id="passwordbox" required="true" placeholder="Password">
<input type="text" name="username" id="usernamebox" required="true" placeholder="Username">
</table>
</form>
I send the form to my login.php page (includes folder) and process the information and if successful start the session and redirect the user to the home.php page. When I click submit to log me in I am brought to an error saying:
Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in /Applications/XAMPP/xamppfiles/htdocs/VolleypagesFixed/includes/login.php on line 14
Warning: mysqli_error() expects parameter 1 to be mysqli, resource given in /Applications/XAMPP/xamppfiles/htdocs/VolleypagesFixed/includes/login.php on line 14
This line is on my log in page and this is the code for that page:
<?php
// start the session
session_start();
require_once ('connect.php');
// if form is submitted
if(isset($_POST['username']) and isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM `users` WHERE username='$username' and password='$password'";
line 14 - $result = mysqli_query($con, $query) or die(mysqli_error($con));
$count = mysqli_num_rows($result);
// create session if values are equal
if($count == 1) {
// cookie is set
if(isset($_COOKIE['ID'])) {
$id = mysql_real_escape_string($_COOKIE['ID']);
}
if(!isset($id)){
die("Cookie not found");
}
} else {
echo "Invalid Login";
header("Location: http://localhost/FolderName/index.php");
}
}
// if user is logged in redirect
if(isset($_COOKIE['ID'])) {
header("Location: http://localhost/FolderName/home.php");
}
?>
Any help on the error on line 14 or any advice and how I have set my login up would be very helpful!
</div>