您好我有一个用于搜索的页面,但我收到以下错误
试图在..........
中获取非对象的属性有同样的问题,但我没有找到我的问题的答案。
以下是代码:
<html>
<head>
</head>
<body>
<form action="" name="myform" method="post">
<table width="1330" border="0" align="center">
<tr><td colspan="45" align="left"><a href="../Admin Panel.php"><img src="../Images for admin panel/backbutton.jpg" /></a></td></tr>
<th height="47" colspan="11"><font size="+3">Remote Employee Search Page</font></th></tr>
</tr>
</tr>
<th colspan="11"><input type="text" name="search" size="33"> <input type="submit" id="Submitbutton" value="Search" style=" font: 15px verdana;
text-decoration: none;
background-color: #EEEEEE;
color: #333333;
padding: 2px 6px 2px 6px;
border-top: 1px solid #CCCCCC;
border-right: 1px solid #333333;
border-bottom: 1px solid #333333;
border-left: 1px solid #CCCCCC;
cursor:pointer;"><br ></th></tr>
<?php
require_once('../db.php');
@$search = $_POST['Search'];
$query = "SELECT
RemoteEmployeeID,
RemoteEmployeeFullName,
RemoteEmployeeNIC,
RemoteEmployeePassword,
RemoteEmployeePhone,
RemoteEmployeeEmail,
PDName, DistrictName,
ProvinceName,
RemoteEmployeeRegion,
RemoteEmployeeExactAddress,
Bank, BeneficiaryName,
AccountNumber,
AccountType,
ContractDate,
ContractExpirationDate
FROM remoteemployees, properties
WHERE RemoteEmployeeID = '".$search."' OR RemoteEmployeeEmail = '".$search."' OR RemoteEmployeeFullName = '".$search."'";
$query_run = $connection->query($query);
if($query_run->num_rows == 0)
{
exit("<center><font color='red'><strong>Sorry, No Records Found For Your Search</strong></font></center>");
} ?>
<tr><th>R.E.ID</th><th>R.E.FullName</th><th>R.E.Password</th>
<th>R.E.Phone</th><th>R.E.Email</th><th>Status</th><th>More</th>
</tr>
<?php
if( $connection->error ) exit( $connection->error );
while($row=$query_run->fetch_assoc())
{
?>
<tr><td><?php echo $row['RemoteEmployeeID'] ?></td><td><?php echo $row['RemoteEmployeeFullName'] ?></td><td><?php echo $row['RemoteEmployeePassword'] ?></td>
<td><?php echo $row['RemoteEmployeePhone'] ?></td><td><?php echo $row['RemoteEmployeeEmail'] ?></td>
<td><a href= "More About Remote Employees.php?RemoteEmployeeID=<?php echo $row['RemoteEmployeeID'] ?>" style="color:#FFF;"><img src="../Images for admin panel/zoom.png"></a></td>
</tr>
<?php }
?>
<tr><td colspan="7"><input type="button" value="Print Current Page" onClick="window.print()" style=" font: 15px verdana;
text-decoration: none;
background-color: #EEEEEE;
color: #333333;
padding: 2px 6px 2px 6px;
border-top: 1px solid #CCCCCC;
border-right: 1px solid #333333;
border-bottom: 1px solid #333333;
border-left: 1px solid #CCCCCC;
cursor:pointer;"></td></tr>
</table>
</form>
</body>
</html>
答案 0 :(得分:0)
执行查询后,应检查$query_run
是否为false,然后检查连接错误消息是否为false。如果查询失败,则$query_run
将不是对象。
您也应该使用query()
,因为您使用的是用户输入(prepare()
),所以您应该使用$_POST
。准备好的语句将保护您的数据库不被SQL注入操纵或销毁。