2012-11-26 41 views
-2

我有一个html文件,它创建一个链接到php文件并允许多参数数据库搜索的表单。无论出于何种原因,该文件没有阅读,并且出现错误,这使得很难测试我的sql查询并验证它是否有效。提前致谢。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>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> 
+4

和什么是错误...? – sachleen

+0

请发布错误信息。还请确定代码中导致错误的行。 – paulsm4

+0

这是打connect_errno错误和打印“无法连接到MySQL”等,随后显示我的所有PHP代码到网页。我已经验证了数据库,用户名和密码都是正确的。 – user1852050

回答

0
$mysqli = new mysqli("$database", "$username", "$password", "$username"); 

首先,你不必放在双引号中的变量。

所以,这将是这样的:

$mysqli = new mysqli($database, $username, $password, $username); 

而且也,其中,是变量的值$database$username$password$username界定?您应该在使用它之前设置值!

+0

正如我上面所说的,我已经从代码中删除了我的用户名和密码。实际上,他们在报价中。 – user1852050

+0

如果您正在对值进行硬编码,则只需要将值放在双/单引号中。否则,只传递变量。另外,下次你发布这样的问题时,如果你已经拿下这些值来保护它,请在初始文章中提及它。或者只包含变量,然后掩盖它们。说,使用'***'或'xxxx'作为值。谢谢。 –