Am getting the following error message: Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string() in C:\xampp\htdocs\mine\server.php:12 Stack trace: #0 C:\xampp\htdocs\mine\register.php(1): include() #1 {main} thrown in C:\xampp\htdocs\mine\server.php on line 12
Here's my code:
<?php
     $username = "";
     $email = "";
     $errors = array();
    //connect to the database
    $db = mysqli_connect('localhost', 'root', '', 'registration');
    //if the register button is clicked
    if (isset($_POST['register'])) {
        $username = mysql_real_escape_string($_POST['username']);
        $email = mysql_real_escape_string($_POST['email']);
        $password_1 = mysql_real_escape_string($_POST['password_1']);
        $password_2 = mysql_real_escape_string($_POST['password_2']);
        //to ensure that the form fields are filled properly
        if (empty($username)) {
            array_push($errors, "Username is required");
          }
          if (empty($email)) {
            array_push($errors, "Email is required");
          }
          if (empty($password_1)) {
            array_push($errors, "Password is required");
          }
          if($password_1 != $password_2){
            array_push($errors, "The two passwords do not match");
          }
          //if there's no errors, save the user to database
          if(count($errors)==0) {
            $password = md5($password_1); //encrypt password before storing to database (security)
            $sql = "INSERT INTO users (username, email, password)
                         VALUES ('$username', '$email', 'password')";
             mysqli_query($db,$sql);
          }
    }
  ?>
