PHP-登入次数问题, 出现Trying to get property of non-object
要设计个网页(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');
}
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
建议你先打印出$row的数据.看有没有数据出来.根据你提供的报错信息意思属性不是一个对象.但是在27行没有发现用属性的东西.所以在27行之前断点检查下.