I have a really hard time cracking this nut.
MySQL database consist of the following columnnames: id, stores, results
.
I have a button inside a form. When I click the button "Select", the columnname records
should update with +1. Everytime I click the button I get the error:
Notice: Undefined index: id in /Applications/MAMP/htdocs/practiceProject/updaterecords.php on line 8
Updated Succesfull
I was reading on stackoverflow that it is because I am not getting the value of the id. Therefore I added $id = $_POST['id'];
, but still getting the same error.
Does anybody have an idea what there is going wrong here?
index.php
<form action="updaterecords.php" method="post">
<button type="submit" name="selectstore" >Select</button>
<?php include 'updaterecords.php' ?>
<button type="button" data-dismiss="modal">Close</button>
</form>
updaterecords.php
<?php error_reporting(E_ALL); ini_set('display_errors', 1);
if (mysqli_connect_errno()) { echo "Error: no connexion allowed : " . mysqli_connect_error($mysqli); }
?>
<?php
include 'dbconnection.php';
if(isset($_POST['selectstore'])) {
$id = $_POST['id']; // Line 8
$stmt = $mysqli->prepare("UPDATE stores SET records = records + 1 WHERE id= ?");
$stmt->bind_param('i', $id);
if ($stmt->execute()) {
$success = true;
}
$stmt->close();
$mysqli->close();
if($success) {
echo "Updated Succesfull";
} else {
echo "Failed: " . $stmt->error;
}
}
?>