2017-07-10 28 views
-6

我大家,香港專業教育學院編寫了一個腳本,最近似乎也不錯,但是當我去我的網頁上在本地主機上,香港專業教育學院這樣的錯誤:檢查我的index.php請

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

+0

和錯誤是????????????????? – rtfm

+0

..除了使用mysql_編寫新代碼_ * – rtfm

+2

*一個錯誤*是一個絕對無用的問題描述。當你收到錯誤信息時,會出現一條錯誤信息。它正好在你面前的屏幕上。有**零**的理由,你不要把它包括在你的問題在這裏。你問我們**免費幫助**解決**你的問題**。您應該儘可能方便地爲我們提供相關信息,這些信息在您面前**。 –

回答

1

我要胡亂猜測,說你正在使用PHP 7,我也假設你有沒有看實際的文件˚F或者它告訴你的功能不存在。

讓我們閱讀文檔好嗎 - 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.

小心,建議,並保持它接近你的靈魂。當你在那裏時,瞭解參數化以及在有人刪除所有數據之前爲什麼它是至關重要的。

+1

該評論使我的一天 –

+0

而不是答案,你應該投票關閉這個作爲這個https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in- php – Machavity

+0

我已經投了票:-) –