I'm currently programming a script to login the user if the user types the right information in the Password- and Login-field on a login page. The script is working just fine, but I don't actually know what these two lines of code means and does for the overall user experience.
I'm soon going to an exam where I have to explain the meaning of the code, and it would be absolutely amazing if you guys helped me out by explaining what the two lines of code does below. This is the full script:
<?php
require('db_connect.php');
if (isset($_POST['user_id']) and isset($_POST['user_pass'])) {
$username = $_POST['user_id'];
$password = $_POST['user_pass'];
$query = "SELECT * FROM dataforlogin WHERE username='$username' and password='$password'";
$result = mysqli_query($connection, $query) or die(mysqli_error($connection));
$count = mysqli_num_rows($result);
if ($count == 1) {
header("location: ../staudal/dashboard/index.php");
} else {
echo "Fail";
}
}
?>
The two lines of code that I'm having trouble understanding is:
$result = mysqli_query($connection, $query) or die(mysqli_error($connection));
$count = mysqli_num_rows($result);
What do they do and why?