mySQLi准备失败,多个?从形式

时间:2012-11-26 06:03:47

标签: php html mysql sql mysqli

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

SQL在myPHP管理员中运行,但我从mySQL中收到了一堆丑陋的错误。

当前错误

  

准备失败:(1054)'字段列表'中的未知列'Employee.Fname'   致命错误:在非对象中调用成员函数bind_param()   第41行/nfs/stak/students/g/greenjas/public_html/employee_info.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();
?>

1 个答案:

答案 0 :(得分:1)

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

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