2016-12-21 67 views
-2

我剛剛開始使用PHP,需要MySQL中簡單代碼的幫助,我認爲我需要它在MySQLi中,因爲我得到一個錯誤 我已經將PHP代碼更改爲下面和現在收到以下錯誤:MySQL到MySQLi轉換

!) Notice: Use of undefined constant searchengine - assumed 'searchengine' in C:\wamp\www\search\results.php on line 6 
Call Stack 
# Time Memory Function Location 
1 0.0004 242504 {main}() ...\results.php:0 

索引頁

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Helpy Search Engine</title> 
</head> 
<body> 
    <h1>Go ahead, search.</h1> 
    <form action="results.php" method="get"> 
     <input type="text" name="query" placeholder="Search.."> 
     <button type="submit">Search</button> 
    </form> 
</body> 
</html> 



<?php 

    $search = $_GET['query']; 

    ($GLOBALS["___mysqli_ston"] = mysqli_connect("localhost", "root", "")) or die(((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false))); 
    ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE " . searchengine)); 

    $query = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM results WHERE title LIKE '%".$search."%'"); 
    if(mysqli_num_rows($query) >= 1) { 
     while($a = mysqli_fetch_array($query)) { 
      echo "<a href='".$a['url']."'>".$a['title']."</a><p>".$a['description']."</p><hr/>"; 
     } 

    } else { 
     echo "Oh no! Nothing was found."; 
    } 


?> 
+2

你沒有嘗試過什麼嗎?有你知道的手冊 –

+0

在閱讀了一些更多的手冊後,我已經更新了我的代碼,如上所述。 – Bill04

+0

此代碼中存在SQL注入漏洞,請在上線前修復此問題!搜索「SQL注入MySQLi」以瞭解更多信息。 – halfer

回答

0

好了,所以想通了。我把'searchengine',而不是隻在第6行的searchengine

排序。