登入次数问题, 出现Trying to get property of non-object
2014-12-19 来自:太阳下的小花花 1 人回应

要设计个网页(login_process.php)重另外一个网页(login.php)获得资料,避免有人不断重复登入,3次登入则导向注册页面(register.php), 但是现在我在login_process.php的第27行出现 Trying to get property of non-object这个错误,有人能告诉我这是为什么吗?
以下是我的login_process.php的代码:

<?php
$conn = mysql_connect("localhost", "root", "");
if(!$conn){
die('Could not connect'. mysql_error());
}
mysql_select_db("logindb", $conn);

if(isset($_POST['Submit'])){
if(empty($_POST['Username']) || empty($_POST['Password'])){
echo "You should fill in all the forms before you submit!";
exit;
}

$username = $_POST['Username'];
$password = $_POST['Password'];
$attempts = $_POST['login'];

$query = "SELECT username, password FROM `logint` WHERE username='$username' and password='$password'";
$result = mysql_query($query);

if(!$result){
// Cannot connect to mysql
echo "The query failed " . mysql_error();
} else {
// Connect to mysql
$row = mysql_num_rows($result);
if($row['username'] != $username && $row['password'] != $password) {
if(isset($_POST['login'])){
if($_POST['login'] <= 3){
// Less than 3 attempts
$attempts = $_POST['login'] + 1;
echo 'You had made $attempts times error, please try again. (Maximum 3 times)';
?>
<form name="login_process" method="post" action="login.php">
<input type = "hidden" name = "">
</form>
<?php
} else {
// More than 3 attempts
?>
<script type="text/javascript">
alert("You had made more than 3 times wrong, PLEASE Register first!");
</script>
<?php
header('location:register.php');
}
}
}
}
}
2014-12-19 来自:晓晓.V

建议你先打印出$row的数据.看有没有数据出来.根据你提供的报错信息意思属性不是一个对象.但是在27行没有发现用属性的东西.所以在27行之前断点检查下.

您的回应

你还未登陆,不能回应!登陆