我正在尝试创建一个多字段搜索选项。表单中有四个字段,用户可以在任意一个或多个字段中输入信息,它将查询数据库。
SQL 在 myPHP 管理中工作,但我从 mySQL 中收到一堆丑陋的错误。
当前错误
Prepare failed: (1054) Unknown column 'Employee.Fname' in 'field list' Fatal error: Call to a member function bind_param() on a non-object in /nfs/stak/students/g/greenjas/public_html/employee_info.php on line 41
这里是表单代码:
<!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();
?>
最佳答案
Linux 中 Mysql 表名区分大小写。请参阅以下文档:http://dev.mysql.com/doc/refman/5.1/en/identifier-case-sensitivity.html
因此,如果实际表是“EMPLOYEE”,那么您不能将其称为“Employee”。
关于php - mySQLi 准备失败,多个?从形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13559464/