-6

I everybody, ive coded a script recently seems to be good but when i go to my page on on localhost, ive an error like this:

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /srv/http/index.php:11 Stack trace: #0 {main} thrown in /srv/http/index.php on line 11

<?php

error_reporting(E_ALL); ini_set('display_errors', 1);

$db_hostname = '127.0.0.1';
$db_username = 'root';
$db_password = 'mypass';
$db_database = 'my database name';


    $connect = mysql_connect("$db_hostname","$db_username","$db_password");

    if (!$connect)
        {
           die('Could not connect: ' . mysql_error());
        }

    mysql_select_db($db_database) or die ("could not find db");



    $output ='';



    if (isset ($_POST['search'])){

    $search = $_POST['search'];
    }


    $query = mysql_query("SELECT * FROM user WHERE email LIKE '%".$search."%'" ) or die("could not search");

    $count = mysql_num_rows($query);
    
        if($count == 0){

        $output = 'There was no search results !';
        }

    
    else{

        while($row = mysql_fetch_array($query)){
        $fname = $row['search];
        $output .='<div> '.$fname.'</div>';
        }

        }
}

?>

<!DOCTYPE html>
<html lang="en">
  <head>
      <meta charset=utf-8" />
      <title>Lookup</title>
  </head>
  <body>

<form action="index.php" method="post">
<input type="text" placeholder="search" name="search">
<input type="submit" value=">>"/>

</form>



<?php

print("$output"); 

?>

  </body>
</html>

And this is what the page return

Pentester
  • 11
  • 3
  • and the error is????????????????? –  Jul 10 '17 at 22:44
  • .. apart from writing new code using mysql_* –  Jul 10 '17 at 22:45
  • 2
    *ive an error* is an absolutely useless problem description. When you get the error, there's an error message that comes with it. It's right on the screen in front of you. There is **zero** excuse for you not to include it in your question here. You're asking us for **free help** to solve **your problem**. You should be making it as easy as possible for us to do so by giving us the relevant information that is **right in front of you**. – Ken White Jul 10 '17 at 22:48
  • Yeah its true but: error_reporting(E_ALL); ini_set('display_errors', 1); dont show nothin ive just an 500 internal error – Pentester Jul 10 '17 at 22:54
  • Then at least put a screenshot in your question so we can see that – Keith M Jul 10 '17 at 23:11
  • At first look you don't have balanced curly braces. So error 500 probably stands for parse error. Also `$fname = $row['search];` should be `$fname = $row['search'];`. – Jirka Hrazdil Jul 10 '17 at 23:21
  • its true this is my error: Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /srv/http/index.php:11 Stack trace: #0 {main} thrown in /srv/http/index.php on line 11 – Pentester Jul 10 '17 at 23:36

1 Answers1

1

I'll take a wild guess and say that you are using PHP 7 and I'll also assume you haven't read the actual documentation for the function it is telling you doesn't exist.

Let's read the docs shall we - http://php.net/manual/en/function.mysql-connect.php

Warning: 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.

Heed that advice and keep it close to your soul. While you are there, learn about parameterization and why it is vital before someone deletes all your data.

Peter Featherstone
  • 7,835
  • 4
  • 32
  • 64