0

我正在尝试创建一个多字段搜索选项。表单中有四个字段,用户可以输入任何一个或多个信息,它会查询数据库。

SQL 在 myPHP 管理员中工作,但我从 mySQL 中得到了一堆丑陋的错误。

当前错误

准备失败:(1054)“字段列表”中的未知列“Employee.Fname”致命错误:调用 /nfs/stak/students/g/greenjas/public_html/employee_info 中非对象的成员函数 bind_param()。第 41 行的 php

这是表单代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

<head>
    <title>Bicycle Store Employees</title>
    <link rel="stylesheet" type="text/css" href="web.css" />
</head>
<body>
    <h1>Bicycle Store Manager</h1>
    <h2>Customized Business Management for Bicycle Stores</h2>

    <h3>FORM: RETRIEVE EMPLOYEE INFORMATION</h3>

    <form action="employee_info.php" method="post">
    <h3>Employee Information</h3>
    <h4>First Name: <input type="text" name="Fname"/>
    Last Name: <input type="text" name="Lname"/></h4>

    <h3>Store Information</h3>
    <h4>
    Department #: <input type="text" name="Dno"/>
    Store #: <input type="text" name="Store_num"/>

    <input type="submit" name="submit" value="SEARCH"/>
    </h4>
    </form>

    <p><a href="index.html">HOME</a></p>

</body>
</html>

这是php

if( $_POST["submit"] ) {
    if (!($stmt =$mysqli->prepare("
            SELECT Fname, Minit, Lname, Phone, Address, Sname, Saddress, Dno, Hourly
            FROM
            (
            SELECT LOCATION.*,
            Employee.Fname,
            Employee.Minit,
            Employee.Lname,
            Employee.Address,
            Employee.Hourly,
            Employee.Dno,
            Employee.Phone
            FROM EMPLOYEE, DEPARTMENT, LOCATION
            WHERE EMPLOYEE.Dno=DEPARTMENT.Dnumber AND
            LOCATION.Store_num=DEPARTMENT.Store_num AND
            (Fname='?' OR Lname='?' OR Dno='?' OR LOCATION.Store_num ='?')) X"))) {
            print "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
    }
    if (!$stmt->bind_param("ssii",$_POST['Fname'], $_POST['Lname'], $_POST['Dno'], $_POST['Store_num'])) {
        print "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
    }
    if (!$stmt->execute()) {
        print "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
    }
    $stmt->store_result();

    if (!$stmt->bind_result($Fname,$Minit,$Lname,$Phone,$Address,$Slocation,$Saddress,$Dno,$Hourly)) {
            print "Binding output parameters failed: (" . $stmt->errno . ") " . $stmt->error;
    }
    if ($stmt->num_rows == 0){
        print "No results were found for the following search <p>"
        .$_POST['Fname'].$_POST['Lname'].$_POST['Store_num'].$_POST['Dno']."</p>";
        }
    else {
        print "<table border=2 cellpadding=4>
            <tr bgcolor=white>
            <th>First Name</th>
            <th>Middle Initial</th>
            <th>Last Name</th>
            <th>Phone</th>
            <th>Address</th>
            <th>Store</th>
            <th>Store Location</th>
            <th>Dept #</th>
            <th>Hourly Rate</th>
            </tr>";
        while ($stmt->fetch()){
            print "<tr><td>".$Fname."</td><td>".$Minit."</td><td>".$Lname.
            "</td><td>".$Phone."</td><td>".$Address."</td><td>".$Slocation."</td>
            <td>".$Saddress."</td><td>".$Dno."</td><td>".$Hourly."</td></tr>";
        }
        print "</table>";
    }
$stmt->free_result();
}

$mysqli->close();
?>
4

1 回答 1

1

Mysql 表名在 linux 中区分大小写。请参阅以下文档:http ://dev.mysql.com/doc/refman/5.1/en/identifier-case-sensitive.html

因此,如果实际表是“EMPLOYEE”,那么您不能将其称为“Employee”。

于 2012-11-26T06:18:40.210 回答