Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

are you sure button sql databse

I want to make an "Are you sure?" button before any changes to my database are made.

The form and code that I use are the following, can anyone help me with this cause I can’t figure it out

<form method="post" action="php_code.php" >
    <div class="input-group">
        <input type="hidden" name="id" value="<?php echo $id; ?>">
        <label>Inkoopprijs</label>
        <label>
            <input type="number" step="any" name="inkoopprijs" value="">
        </label>
    </div>
    <div class="input-group">
        <label>Verkoopprijs</label>
        <label>
            <input type="number" step="any" name="verkoopprijs" value="">
        </label>
    </div>
    <div id="product" class="input-group">
        <label>product</label>
        <label>
            <input type="text" name="producten" value="">
        </label>
    </div>

    <div class="input-group">
        <?php if ($update == true):?>
            <button onclick="update_time" class="btn" type="submit" name="update" style="background: darkorange;" >Update</button>
        <?php else: ?>
            <button class="btn" type="submit" name="save" >Save</button>
        <?php endif ?>
        <a class="btn" href="index.php">Home</a>
    </div>
</form>
if (isset($_POST['update'])) {
    $id = $_POST['id'];
    $inkoopprijs = $_POST['inkoopprijs'];
    $verkoopprijs = $_POST['verkoopprijs'];
    $last_modified = $_POST['last_modified'];

    mysqli_query($db, "UPDATE prijzen SET inkoopprijs='$inkoopprijs', verkoopprijs='$verkoopprijs', last_modified= '$last_modified' WHERE id=$id");
    $_SESSION['message'] = "price updated!";
    header('location: C_R_U_D.php');

`

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

i have tried alerts, and even after i hit cancel it still did the editing

>Solution :

You can add onclick event handler to your Save or Update button. Once the button is clicked, call built-in confirm() function that returns true or false depending on user’s choice. In case of false, you would like to prevent browser’s default behavior and cancel form submission, which may be achieved by calling event.preventDefault().

<button type="submit" onclick="confirm('Are you sure?') || event.preventDefault()">Save</button>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading