-1
  <?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.

Gopal Bhuva
  • 654
  • 2
  • 13
  • 20
A M
  • 15
  • 4
  • Mixing **mysqli** and **mysql**. **mysql_*** is removed from PHP latest versions. – Sougata Bose Apr 19 '18 at 04:16
  • since you're probably using a newer version of php, you should try ```mysqli_real_escape_string``` as ```mysql_real_escape_string``` was deprecated since php version 5.5 per the docs – Brian Putt Apr 19 '18 at 04:17
  • you are using deprecated version – Bits Please Apr 19 '18 at 04:18
  • You are connecting your database using `mysqli` and using `mysql_real_escape_string``. and `mysql_real_escape_string` was deprecated. update your code like below. $username = mysqli_real_escape_string($db, $_POST['username']); $email = mysqli_real_escape_string($db, $_POST['email']); $password = mysqli_real_escape_string($db, $_POST['password']); $password2 = mysqli_real_escape_string($db, $_POST['password2']); – Anfath Hifans Apr 19 '18 at 04:21
  • Anfath Hifans, I updated the code but it displays the requested URL was not found on this server – A M Apr 19 '18 at 04:27

1 Answers1

1

mysql_ has been deprecated since 5.5:

The mysql extension has been deprecated since PHP 5.5. The mysqli or PDO extension should be used instead. The deprecation has been decided in mysql_deprecation, where a discussion of the reasons behind this decision can be found.

Nirali
  • 1,776
  • 2
  • 12
  • 23