gpt4 book ai didi

php - 添加指向 MySQL 查询的链接

转载 作者:行者123 更新时间:2023-11-30 23:02:19 25 4
gpt4 key购买 nike

<分区>

您好,我是 PHP 和 MySQL 的新手,我正在尝试为作业编写日志页面,但我不确定如何将查询链接到显示已单击的完整查询的另一个页面。基本上这样用户就可以访问他们以前的日记条目。以下是我到目前为止编写的代码:

<?php
session_start();
if(isset($_SESSION['uname'])){
echo "Welcome " . $_SESSION['uname'];
}
require_once 'PHP/Constants.php';
$conn = new MySQLi(DB_SERVER, DB_USER, DB_PASSWORD,DB_NAME) or die ('There was a problem connecting to the database');
$uname = $_SESSION['uname'];
$query="SELECT Username, Date_Created, Title FROM journal";
$result=mysqli_query($conn, $query);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Journal</title>
</head>

<body>
<p>
<h1>My Journal</h1>
</p>
<?php
echo "<table width='400' border='1' cellspacing='0' cellpadding='3'>
<tr>
<th>Date</th>
<th>Title</th>
</tr>";
while ($rows=mysqli_fetch_array($result)){
if($rows['Username']=$uname) {
echo "<tr>";
echo "<td>" . $rows['Date_Created'] . "</td>";
echo "<td>" . $rows['Title'] . "</td>";
echo "</tr>";
} else echo "No Journal Entries Found";
}
echo "</table>";
?>
</table>
<form method="post" action="new_entry.php">
<p>
<input type="submit" id="new_entry" value="New Entry" name="new_entry" />
</p>
</form>
<form method="post" action="choices.php">
<p>
<input type="submit" id="back" value="Back" name="back" />
</p>
</form>
</body>
</html>

预先感谢您的帮助 - 尼克

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com