1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[SQL] How to use a UPDATE clause and a INSERT clause in the same file?

Discussão em 'Outras Linguagens' iniciado por Stack, Setembro 14, 2021.

  1. Stack

    Stack Membro Participativo

    Here is my form in my html page.. the hidden inputs are for the notification INSERT.. and the "text" input & the "range" input are for the UPDATE order progress ALSO the UPDATE statement is working just not the INSERT..

    <form method="POST" action="../PHP/ordprogress.php">

    <input type="hidden" value="<?php echo $fetch['username']?>" name="username">
    <input type="hidden" value="Admin" name="name">
    <input type="hidden" value="Update!" name="notif">
    <input type="hidden" value="Your progress has been updated!" name="details">
    <input type="hidden" value="<?php echo date('Y/m/d H:i:s'); ?>" name="date">
    <input type="hidden" value="unread" name="status">

    <input type="text" name="uid" value="" placeholder="Order Number..">
    <input type="range" step="25" min="0" max="100" value="50" name="ordprogress" class="sliderper" id="myRange">

    <button type="submit" value="Update" name="Update">Update</button>

    And here is my ordprogress.php script, it should just insert a row (notification) after the order progress has been updated..I had it working twice and then I tried to fix something then it stopped working and when I reverted the code it still didn't work lol



    if (isset($_POST['Update'])) {

    $ordprogress = $_POST['ordprogress'];
    $uid = $_POST['uid'];

    $stmt = "UPDATE device_repairs SET ordprogress = :eek:rdprogress WHERE uid = :uid";
    $stmt = $dbh->prepare($stmt);
    $stmt->bindParam(':eek:rdprogress', $_POST['ordprogress'], PDO::pARAM_STR);
    $stmt->bindParam(':uid', $_POST['uid'], PDO::pARAM_STR);

    $uid = $_POST['uid'];
    $username = $_POST['username'];
    $name = $_POST['name'];
    $notif = $_POST['notif'];
    $details = $_POST['details'];
    $date = $_POST['date'];
    $status = $_POST['status'];

    $sql = 'INSERT INTO `notifications` (uid, username, name, notif, details, date, status) VALUES :)uid, :username, :name, :notif, :details, :date, :status)';

    $inst = $dbh->prepare($sql);

    $inst->execute(['uid' => $uid, 'username' => $username, 'name' => $name, 'notif' => $notif, 'details' => $details, 'date' => $date, 'status' => $status]);


    <meta http-equiv="refresh" content="0; URL=https://www.mysite.co.uk/Profile/admin.php" />




    Continue reading...

Compartilhe esta Página