I’ve got an html file that creates a form that links to a php file and allows a multi-parameter search of a database. For whatever reason, the file isn’t reading and I’m getting an error, making it difficult to test my sql query and verify that it works. Thanks in advance.
Here’s the 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>EMPLOYEE INFORMATION</h3>
<?php
ini_set('display_errors', 'On');
$mysqli = new mysqli("$database", "$username", "$password", "$username");
if ($mysqli->connect_errno) {
print "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
if( $_POST["submit"] ) {
if (!($stmt =$mysqli->prepare("SELECT * into tempTable FROM
(SELECT Fname, Minit, Lname, Address, Hourly, Sname, Saddress, Dno
FROM EMPLOYEE
join on Employee.Dno = DEPARTMENT.Dnumber
join on LOCATION.Store_num = DEPARTMENT.Store_num
where Fname = $_POST['Fname'] OR Lname = $_POST['Lname']
OR Stor_num = $_POST['Store_num'] OR Dno = $_POST['Dno']
GROUP BY Store_num);"))) {
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();
?>
<p><a href="employee_info.html">SEARCH AGAIN</a></p>
<p><a href="index.html">HOME</a></p>
</body>
</html>
Take a Look.
mysqli_error,mysqli::$error