note 129964 added to reserved.variables.session
| From: | Anonymous | Date: | Fri, 10 Jan 2025 11:18:10 +0000 |
| Subject: | note 129964 added to reserved.variables.session | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221777@lists.php.net to get a copy of this message | ||
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
?>
<?php 1
$servername = "mysql2";
$username = "root";
$password = "htlkrems";
try {
$conn = new PDO("mysql:host=$servername;dbname=test_php_db", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
//Zum adden von Posts
if($_SERVER['REQUEST_METHOD'] == 'POST' &&
isset($_POST['new'])){
if($_POST['title'] && $_POST['content']){
$stmt = $conn->prepare("INSERT INTO posts (user_id, title, content) VALUES
(:user_id, :title, :content)");
$stmt->bindParam(':user_id', $user_id);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':content', $content);
$user_id = 1;
$title = $_POST['title'];
$content = $_POST['content'];
$stmt->execute();
}
}
//Zum löschen
if($_SERVER['REQUEST_METHOD'] == 'POST' &&
isset($_POST['detail'])){
$stmt = $conn->prepare("DELETE FROM posts where id = :id");
$stmt->bindParam(':id', $_POST['detail']);
$stmt->execute();
}
//ZUm updaten
if($_SERVER['REQUEST_METHOD'] == 'POST' &&
isset($_POST['update'])){
if($_POST['title'] && $_POST['content']){
$stmt = $conn->prepare("UPDATE posts SET title = :title, content = :content
WHERE id = :id");
$stmt->bindParam(':title', $title);
$stmt->bindParam(':content', $content);
$stmt->bindParam(':id', $_GET['detail']);
$title = $_POST['title'];
$content = $_POST['content'];
$stmt->execute();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
crossorigin="anonymous">
<title>Test Ãbung</title>
</head>
<body class="container-fluid pt-5">
<div class="container">
<?php
$stmt = $conn->prepare("SELECT * FROM posts");
$stmt->execute();
$posts = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo '<table class="table table-striped">';
echo "<tr>";
echo "<th>id</th>";
echo "<th>user_id</th>";
echo "<th>title</th>" ;
echo "<th>content</th>" ;
echo "<th>created_at</th>";
echo "</tr>";
foreach ($posts as $post){
echo "<tr>";
echo "<td>" . $post['id'] . "</td>";
echo "<td>" . $post['user_id'] .
"</td>";
echo "<td>" . $post['title'] .
"</td>";
echo "<td>" . $post['content'] .
"</td>";
echo "<td>" . $post['created_at'] .
"</td>";
echo '<td><form method="get"><button
type="submit" name="detail" value="'. $post['id'] .
'" class="btn
btn-primary">Details</button></form></td>';
echo '<td><form method="post"><button
type="submit" name="detail" value="'. $post['id'] .
'" class="btn
btn-danger">Delete</button></form></td>';
echo "</tr>";
}
echo "</table>";
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 193.170.70.27)
----
Manual Page -- https://php.net/manual/en/reserved.variables.session.php
Edit -- https://main.php.net/note/edit/129964
Del: integrated -- https://main.php.net/note/delete/129964/integrated
Del: useless -- https://main.php.net/note/delete/129964/useless
Del: bad code -- https://main.php.net/note/delete/129964/bad+code
Del: spam -- https://main.php.net/note/delete/129964/spam
Del: non-english -- https://main.php.net/note/delete/129964/non-english
Del: in docs -- https://main.php.net/note/delete/129964/in+docs
Del: other reasons-- https://main.php.net/note/delete/129964
Reject -- https://main.php.net/note/reject/129964
Search -- https://main.php.net/manage/user-notes.php