I have tried to search for an answer for hours now and none of the answers on here seem to help.
When I run the code I get the following errors on line 8 ($db_select
):
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in
Warning: mysqli_error() expects exactly 1 parameter, 0 given in
Please can someone tell me what is wrong with this code:
<?php
$servername = "localhost";
$username = "my username";
$password = "my password";
$dbname = "my database";
$tablename ="users";
$connection = mysqli_connect($servername, $username, $password) or die (mysqli_error());
$db_select = mysqli_select_db($tablename, $connection) or die (mysqli_error());
$email = $_POST['email'];
$password = $_POST['password'];
$result = mysqli_query($connection, "SELECT * FROM $tablename WHERE email='$email' and password='$password'");
$count = mysqli_num_rows($result);
if($count==1)
{
session_register("email");
session_register("password");
header("location:loginsuccess.php");
}
else
{
echo "Wrong email or password";
}
?>