0
I’m trying to make a system of login and registration of users in PHP, but I have several problems only in login.php, the registration is working correctly, but the login is presenting the errors: Warning: mysqli_query() expects Parameter 1 to be mysqli, null Given in C: wamp www rifa login.php on line 13 and Warning: mysqli_num_rows() expects Parameter 1 to be mysqli_result, null Given in C: wamp www rifa login.php on line 14, my code is just below, someone has an idea of how I can fix these errors?
<?php
error_reporting (E_ALL & ~ E_NOTICE & ~ E_DEPRECATED);
$hostname = 'localhost';
$username = 'root';
$password = '12345';
$db = 'rifou';
$connection = new mysqli($hostname, $username, $password);
mysqli_select_db($connection, $db);
$nickname = mysqli_real_escape_string($connection, $_POST['nick']);
$password = mysqli_real_escape_string($connection, $_POST['senha']);
$select_user = "SELECT * FROM usuarios WHERE nick='$nickname' AND senha='$senha'";
$run_user = mysqli_query($con, $select_user);
$check_user = mysqli_num_rows($run_user);
if ($check_user > 0){
echo "logado";
} else {
echo "não logado";
}
?>
Your connection is not valid.
– rray
What do you mean? The code cannot connect to db?
– Vinicius Costa Castro
When I edited my code for the one described in http://www.w3schools.com/php/php_mysql_select.asp it worked perfectly, but not the way I want it to, but not the way I want it to work.
– Vinicius Costa Castro
Do this in select, use the mysqli_query parameter, and call the $Connection variable first.
– Gonçalo