-2

i need to retrieve the username from the table users but i am using mysql_real_escape_string but it is giving me the error :

( ! ) Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string() in C:\wamp64\www\final-project\profile.php on line 4
( ! ) Error: Call to undefined function mysql_real_escape_string() in C:\wamp64\www\final-project\profile.php on line 4
Call Stack
#   Time    Memory  Function    Location
1   0.0014  368024  {main}( )   ...\profile.php:0

the code is :

<?php include("./inc/header.inc.php");?>
<?php
if(isset($_GET['u'])) {
    $username = mysql_real_escape_string($_GET['u']);
    if(ctype_alnum($username)){
        //check if user exist
        $check = DB::query("SELECT username FROM users WHERE username='$username'");
        if(mysql_num_rows($check)==1){
        $get = mysql_fetch_assoc($check);
        $username = $get['username'];
        }else{
            echo "<meta http-equiv=\"refresh\"0; url=http://localhost/final-project/index.php\">";
            exit();
        }
    }
}
?>

<h2>Profile page for : <?php echo "$username";?></h2>

the if(isset($_GET['u'])) is returning the username

karim
  • 1
  • 1
  • 1
  • 7

1 Answers1

-1

It was removed in PHP7.

Per the documentation:

http://php.net/manual/en/function.mysql-real-escape-string.php

This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information.

dave
  • 62,300
  • 5
  • 72
  • 93
  • fred i know that it is duplicated but i didn't know how to fix it thank you for your time – karim Oct 24 '17 at 21:13