<?php
session_start();
$db = mysqli_connect("localhost","root", "", "authentication");
if (isset($_POST['regbtn'] )) {
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
$password = mysql_real_escape_string($_POST['password']);
$password2 = mysql_real_escape_string($_POST['password2']);
if ($password == $password2) {
$password = md5($password);
$sql = "INSERT INTO users(username, email, password)
VALUES('$usrname','$email','$password')";
mysqli_query($db, $sql);
$_SESSION['message']="You are now logged in";
$_SESSION['username']= $username;
header("location: home.php");
}else{
$_SESSION['message']="The two passwords do not match";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title> Registration</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="header">
<h1> Registration </h1>
</div>
<form method="post" action="register.php">
<table>
<tr>
<td> Username:</td>
<td><input type="text" name="username" class="textInput">
</td>
</tr>
<tr>
<td> Email:</td>
<td><input type="email" name="email" class="textInput"></td>
</tr>
<tr>
<td> Password:</td>
<td><input type="password" name="password" class="textInput">
</td>
</tr>
<tr>
<td> Confirm Password:</td>
<td><input type="password" name="password2"
class="textInput"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="regbtn" value="Register"></td>
</tr>
</table>
</form>
</body>
</html>
When i am trying to run it on xampp, this is what the they say :
Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string() in C:\xampp\htdocs\authentication\register.php:7 Stack trace: #0 {main} thrown in C:\xampp\htdocs\authentication\register.php on line 7
since the line 7 is :
$username = mysql_real_escape_string($_POST['username']);
I wanna know what is wrong here and how can I find solution to this problem. Thank you.