I'm creating a simple php login page based on in this video .
However, after doing exactly as the video describes, I learned that my PHP version has updated and can not use the command mysql_connect
.
<?php
// Get values passe from form in login.php file
$username = $_POST['user'];
$password = $_POST['pass'];
//to prevent mysql injection
$username = stripcslashes($username);
$password = stripcslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
//connect to the server and select database
mysql_connect("localhost", "root", "");
mysql_select_db("projeto_rc");
//Query for database user
$result = mysql_query("SELECT * FROM utilizadores WHERE username = '$username' and password = '$password'")
or die("Failed to query database ".mysql_error());
$row = mysql_fetch_array($result);
if ($row['username'] == $username && $row ['password'] == $password){
echo "Login success!!! Welcome ".$row['username'];
}
else {
echo "Failed to login";
}
Based on this code, how can I change it to support the minimum version of PHP 7? I know I should start by changing from mysql_real_escape_string
to mysqli_real_escape_string
as indicated by this error:
Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string () in C: \ xampp \ htdocs \ login \ process.php: 9 Stack trace: # 0 {main} thrown in C: \ xampp \ htdocs \ login \ process.php on line 9
However, I would need to use 2 parameters between parentheses and just use one. What are some possible solutions?