我有一个html文件,它创建一个链接到php文件的表单,并允许对数据库进行多参数搜索。无论出于何种原因,文件都没有读取,我收到错误,因此很难测试我的sql查询并验证它是否有效。提前谢谢。
以下是代码:
<!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>
答案 0 :(得分:0)
答案 1 :(得分:0)
$mysqli = new mysqli("$database", "$username", "$password", "$username");
首先,您不必将变量括在双引号中。
所以,就像这样:
$mysqli = new mysqli($database, $username, $password, $username);
此外,变量$database
,$username
,$password
和$username
的值定义在哪里?您应该在使用之前设置值!