[PHP-NOTES] note 130344 added to mysql-xdevapi-crudoperationlimitable.limit

[email protected] ("[email protected]")
Newsgroups php.notes
Message-ID <[email protected]>
<?php
$servername = "mysql";
$username = "root";
$password = "htlkrems";

session_start();

try {
    $conn = new PDO("mysql:host=$servername;dbname=students", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $stmt = $conn->prepare("SELECT * FROM students");
    $stmt->execute();
    $students = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch(PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}

/* echo "<h4>Cookie Student:</h4>";
$cookie_name = 'name';
$cookie_value = $students[0]['first_name'] . ' ' . $students[0]['last_name'];
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/");
echo $cookie_name . ": " . $cookie_value . "\n";

echo "<br>";

echo "<h4>Session Students:</h4>";
for ($i = 0; $i < count($students); $i++)
{
    echo $_SESSION['first_name'] = $students[$i]['first_name'] . "\n";
    echo $_SESSION['last_name'] = $students[$i]['last_name'] . "<br>";
} */

if(isset($_POST['create_student']))
{
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $class = $_POST['class'];

    $query = "INSERT INTO students (first_name, last_name, email, phone, class)
    VALUES (:first_name, :last_name, :email, :phone, :class)";
    $query_run = $conn->prepare($query);

    $data = [
        ':first_name' => $first_name,
        ':last_name' => $last_name,
        ':email' => $email,
        ':phone' => $phone,
        ':class' => $class
    ];

    $query_execute = $query_run->execute($data);
    header('Location: ' . $_SERVER['PHP_SELF']);
}

if(isset($_POST['update_student']))
{
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $class = $_POST['class'];
    $student_id = $_POST['student_id']; // aus verstecktem Inputfeld im Modal

    $query = "UPDATE students SET first_name = :first_name, last_name = :last_name, email = :email, phone = :phone, class = :class WHERE id = :id";
    $query_run = $conn->prepare($query);

    $data = [
        ':first_name' => $first_name,
        ':last_name' => $last_name,
        ':email' => $email,
        ':phone' => $phone,
        ':class' => $class,
        ':id' => $student_id
    ];

    $query_execute = $query_run->execute($data);
}

if(isset($_POST['delete_student']))
{
    $student_id = $_POST['delete_student'];
    $query = "DELETE FROM students WHERE id = :id";
    $query_run = $conn->prepare($query);
    $query_execute = $query_run->execute(['id' => $student_id]);
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 193.170.70.27)
----
Manual Page -- https://php.net/manual/en/mysql-xdevapi-crudoperationlimitable.limit.php
Edit        -- https://main.php.net/note/edit/130344
Del: integrated  -- https://main.php.net/note/delete/130344/integrated
Del: useless     -- https://main.php.net/note/delete/130344/useless
Del: bad code    -- https://main.php.net/note/delete/130344/bad+code
Del: spam        -- https://main.php.net/note/delete/130344/spam
Del: non-english -- https://main.php.net/note/delete/130344/non-english
Del: in docs     -- https://main.php.net/note/delete/130344/in+docs
Del: other reasons-- https://main.php.net/note/delete/130344
Reject      -- https://main.php.net/note/reject/130344
Search      -- https://main.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.