I'm trying to create a multi field search option. There are four fields in the form and the user can enter info into any one or multiples, and it will query the db.
The SQL works in myPHP admin, but I'm getting a bunch of ugly errors from mySQL.
current error
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
Here is the form code:
<!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>
And here is the 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();
?>
Mysql table names are case sensitive in linux. See this bit of documentation: http://dev.mysql.com/doc/refman/5.1/en/identifier-case-sensitivity.html
So if the actual table is "EMPLOYEE" then you can't refer to it as "Employee".