在里面
Index.php
-您没有正确设置$起始值。以下代码集
$start
值来自
$_POST['start']
如果不存在
$开始
默认值为0。
而且您也没有正确接受表单提交。我修改了代码,通过对它们的$\u POST变量进行isset()检查来接受这两种提交类型(next和login)。
使用:
<?php
include_once('User.php');
if(isset($_POST['submit']) OR isset($_POST['next'])){
$username = $_POST["user"];
$password = $_POST["pass"];
$object = new User();
$object->username= $username;
$object->Password=$password;
if( $object->isAuthenticated() ){
echo "User Verified . <br><br>";
$start = 0;
if(isset($_POST['start'])){
$start = $_POST['start'];
}
$object->getBooks($start);
}
}
else{
echo "Wrong User Name Or Password . <br>";
}
?>
在表单代码中,必须添加一个隐藏输入,该输入保存下一条数据库记录的偏移量值。
使用此代码:
<form method="post" action="">
Name: <input type="text" name="user" value="<?php echo $user;?>">
<span class="error">* <?php echo $nameErr;?></span>
<br><br>
password: <input type="password" name="pass" value="<?php echo $password;?>" >
<span class="error">* <?php echo $passwordErr;?></span>
<br><br>
<input type="submit" name="submit" value="Login">
<br><br>
<input type="hidden" value="<?php echo (intval(isset($_POST['start'])?$_POST['start']:0)+1);?>" name="start"/>
<button type="button" name="button" onclick="window.location.href='/ooRigester.php'">SignUp</button>
<br><br>
<input type='submit' name='next' value='next' method="post"><br>
</form>
你的课堂方法
getBooks()
必须有
$开始
参数,以便它知道下一个要显示的记录。
尝试:
public function getBooks($start = 0)
{
$limit = 1;
//SELECT loginUser.username, Library.nameOfBook FROM loginUser JOIN userBook JOIN Library ON userBook.user_id = loginUser.id AND userBook.book_id = Library.id WHERE loginUser.username="loay";
$query = "SELECT Library.nameOfBook FROM loginUser JOIN userBook JOIN Library ON userBook.user_id = loginUser.id AND userBook.book_id = Library.id WHERE loginUser.username=:username LIMIT $start, $limit";
$statment = $this->db->prepare($query);
$statment->execute([
':username' => $this->username
//,':start' => $start, ':limit' => $limit
]);
$result = $statment->fetchAll();
echo "<table border='1'>
<tr>
<th>Books</th>
</tr>";
foreach($result as $row){
echo "<tr>";
echo "<td>" . $row['nameOfBook'] . "</td>";
echo "</tr>";
}
echo "</table>";
}