This is the last page, called the landing page.
Basic code
echo "</table>";
echo "<br/>";
echo "<form action='denglucg.php' method='post'>";
echo "<h2>创建新事项</h2>";
echo "<label><span>题目</span><input type='text' name='title'></label>";
echo "<label><span>最后期限</span><input type='text' name='complete-by' value='YYYY-MM-DD'></label>";
echo "<label><span>描写</span><textarea name='description'></textarea></label>";
echo "<input type='submit' value='创建新事项'/>";
echo "</form>";
First open the session technology, you can get the data stored in the server can be obtained
@session_start();
Then see if you have logged in before and have not logged out, and the page after login is displayed, and
$current_userid=$_SESSION['userid'];
$query = "SELECT id, title,mx,ksdate,wcdate from items WHERE user_id = $current_userid";
It means to save the acquired data in a variable, because every time the data consumption performance of the browser is acquired
, all the data in the items is queried. The condition is that the registered user and the logged-in user are consistent and the information of which user is displayed.
$db=new mysqli('localhost','root','','bb');
$db->set_charset('utf8');
//看看链接成不成功,
if ($db->connect_errno) {
echo "这次链接有问题。,重新登录把";
exit();
}
No need to say it, this
Update operation
if(isset($_POST['completed-item'])) {
$item_id = $_POST['completed-item'];
$completed_query = "UPDATE items set wcdate= '".date("Y-m-d")."' WHERE id = $item_id";
$completed_result = $db->query($completed_query);
if(!$completed_result) {
echo "没有更新";
exit();
}
}
Insert operation
if(isset($_POST['title'])) {
$title = $_POST['title'];
$description = $_POST['description'];
$complete_by = $_POST['complete-by'];
$user_id = $_SESSION['userid'];
$stmt = $db->prepare("INSERT INTO items VALUES (?,?,?,?,?,?)");
$id = NULL;
$completed_on = NULL;
$stmt->bind_param("issssi", $id, $title, $description, $complete_by, $completed_on, $user_id);
$stmt->execute();
if(!$stmt->affected_rows) {
echo "没有插入";
}
}
delete data
if(isset($_POST['item-to-delete'])) {
$item_to_delete = $_POST['item-to-delete'];
$delete_query = "DELETE FROM items WHERE id = $item_to_delete";
$delete_result = $db->query($delete_query);
if(!$delete_result) {
echo "没有删除";
exit();
}
}
Old rule: field_seek (1); skip the first field. , Why, because the user's id starts from 1
$ result-> fetch_field () gets the field
fetch_assoc () associative array
if($result->num_rows) {
echo "<table>";
echo "<caption>我的To-Do List</caption>";
echo "<thead>";
echo "<tr>";
echo "<th>号</th>";
$result->field_seek(1);
while($field = $result->fetch_field()) {
echo "<th>".$field->name."</th>";
}
echo "<th>删除</th>";
echo "</tr>";
echo "</thead>";
for($i = 1; ($row = $result->fetch_assoc()); $i++) {
echo "<tr>";
echo "<td>$i</td>";
echo "<td>".$row['title']."</td>";
echo "<td>".$row['mx']."</td>";
echo "<td>";
if(!$row['ksdate']) {
echo "无最后期限";
} else {
echo $row['ksdate'];
}
echo "</td>";
if(!$row['wcdate']) {
echo "<td>";
echo "<form action='denglucg.php' method='post'>";
echo "<input type='hidden' value='".$row['id']."' name='completed-item' />";
echo "<input type='submit' value='标记为完成了'/>";
echo "</form>";
echo "</td>";
} else {
echo "<td>".$row['wcdate']."</td>";
}
echo "<td>";
echo "<form action='denglucg.php' method='post'>";
echo "<input type='hidden' name='item-to-delete' value='".$row['id']."'/>";
echo "<input type='submit' value='删除'/>";
echo "</form>";
echo "</td>";
echo "</td>";
echo "</tr>";
}
}