我有代码将用户信息注册到数据库,在将它们保存到数据库之前必须检查电子邮件地址是否存在。他们都工作正常,但总是给我一个错误信息:
注意:尝试在第72行的X:\ xampp \ htdocs \ csg2431 \ week4 \ registerUser.php中获取非对象的属性
这是代码表格第72行
$email_query = "SELECT EmailAddress FROM userdetails WHERE EmailAddress = '".$emailAddress."'";
$email_results = $db->query($email_query);
if (isset($emial_results))
{
$error_message ='Your database is empty.';
}
if ($email_results->num_rows > 0) // this is line 72
{
$error_message = 'Your email address already exists, choose anther.';
}
if ($error_message != '')
{
echo 'Error: '.$error_message. '<a href="javascript: history.back();">Go Back</a>.';
echo '</body></html>';
exit;
}
它也发生在我的其他页面上,用于搜索数据库中的用户信息,
注意:尝试在第43行的X:\ xampp \ htdocs \ csg2431 \ week4 \ searchUsers.php中获取非对象的属性
这里有一些代码:
$results = $db->query($query);
echo '<p>'.$results->num_rows.' users found.</p>'; // this is line 43
while ($row = $results->fetch_assoc())
{
echo '<p><strong>Name: </strong>'. $row['Surname'].','.$row['FirstName'].'<br />';
echo '<strong>Gender: </strong>'. $row['Gender'].',<br />';
echo '<strong>Date of Birth: </strong>'. $row['DOB'].',<br />';
echo '<strong>Home Phone: </strong>'. $row['HomePhone'].',<br />';
echo '<strong>Position: </strong>'. $row['Position_ID'].',<br />';
echo '<strong>Room Number: </strong>'. $row['RoomNo'].',<br />';
echo '<strong>Work Phone: </strong>'. $row['WorkPhone'].',<br />';
echo '<strong>Fax: </strong>'. $row['Fax'].',<br />';
echo '<strong>Mobile: </strong>'. $row['mobilePhone'].',<br />';
echo '<strong>Email: </strong>'. $row['EmailAddress'].',<br />';
echo '<strong>Department: </strong>'. $row['Dept_ID'].',<br /></p>';
}
看起来每次我使用num_rows
时都会发生错误