PHP MySQL查询SELECT错误未找到现有表值

时间:2017-08-24 09:17:47

标签: php mysql database forms

我正在尝试创建一个Web应用程序,按ID /名称输入搜索,数据库A(客户端)搜索现有客户端,如果客户端存在,则显示数据库A(信息数据)和数据库B上的值(购买历史记录)每个客户);如果没有,它会显示一个表单,将客户端添加到数据库A,然后将新购买添加到数据库B.

到目前为止,这是我的代码:

index.php - >这是搜索表单:

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <form name = "inicio" action = "inicio.php">
        Mostrar equipamento de:<input type="text" name="user" value="" />
        <input type="submit" value="ir" />
        </form>
    </body>
</html>

这是显示数据库信息的标准:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>ola</title>
    </head>
    <body>

       CLIENTES <?php //chama a ação de index.php
        echo htmlentities($_GET["user"])."<br/>";?>

        <?php
        //declarar variaveis
       $servername = "localhost";
       $username = "phpuser";
       $password = "phpuserpw";
       $dbname = "equipamento";
       $tablename = "clientes";
       $user = "user"; 

       //criar ligação
       $conn = mysqli_connect($servername, $username, $password, $dbname);
       //verifica licação
       if (!$conn) {
           die("Connection failed: " . mysqli_connect_error());  
       }


       //query
       $sql = "SELECT ID, Nome FROM clientes WHERE Nome='" . $user . "'";
       $result = mysqli_query($conn, $sql);


       if(mysqli_num_rows($result) !== 0) {
           //output data de cada fila
           while ($row = mysqli_fetch_assoc($result)) {
               echo "ID: " . $row["ID"]. " Nome: " .$row["Nome"]. "<br>";
           }
       }else {
           echo "O cliente não existe";
       }


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

       mysqli_close($conn);
       ?>

</body>
</html>

我相信错误报告给我的查询,但我没有足够的经验来理解可能出错的地方。 此外,我添加了错误报告脚本,但它没有显示任何错误。 应该在哪里显示?

感谢您的帮助。

0 个答案:

没有答案