Created a form that successfully inserts a record from a form into a SQLite database. Trying to also add a delete button but i am unsure on how to execute the query properly. Here is my code:
index.php
<input id="submit" type="submit" name="input" value="Input">
<input id="submit" type="submit" name="delete" value="Delete">
post.php
if (!empty($_POST['input'])) {
header("location:index.php");
$stmt = $conn->prepare("INSERT INTO stock (name, gender, age) VALUES (:name, :gender, :age)");
$stmt->execute(array(':name' => $_POST['name'],
':gender' => $_POST['gender'],
':age' => $_POST['age']));
}
elseif (!empty($_POST['delete'])) {
header("location:index.php");
$stmt = $conn->prepare("DELETE FROM stock WHERE name = ':name' AND gender = ':gender' AND age = 'age'");
}
isset()rather than!empty()and addexit;after each header.exit;. Once one of them is successfully executed, it will then redirect to the specified URL and stop any further execution of the rest of the script.