I am creating a carpool website and I need help with something. I have created a button and if people click on that button than the value of free spaces in the car will decrement by one(meaning the one who will click it will reserve the place). So this value must be changed in the database and also when I refresh the page it will change on the table where I display info.This is what I have written so far but doesn't seem to make a change.Thanks in advance!
<tbody>
<?php while ($row=mysqli_fetch_array($results)) {
?>
<tr>
<td><?php echo $row['username_krijim']; ?> </td>
<td><?php echo $row['nisja']; ?> </td>
<td><?php echo $row['destinacioni']; ?> </td>
<td><?php echo $row['data_krijim']; ?> </td>
<td><?php echo $row['ora_krijim']; ?> </td>
<td ><?php echo $row['vende_krijim']; ?> </td>
<td><?php echo $row['cmimi_krijim']; ?> </td>
<td><?php echo $row['mesazhi_krijim']; ?> </td>
<td><form action="index_show.php" method="POST"><input class="btn btn-primary" style="background:#f2545f;" type="submit" name="rezervo" value="Rezervo"></form></td>
<?php
if(isset($_POST['rezervo'])){
$id_krijim=$row['id_krijimi'];
$sql = "UPDATE krijo_itinerar SET vende_krijim=vende_krijim-1 WHERE id_krijimi='$id_krijim'";
mysqli_query($db, $sql);
}
?>
</tr>
<?php } ?>
</tbody>
mysqliis significantly less verbose, making code easier to read and audit, and is not easily confused with the obsoletemysql_queryinterface. Before you get too invested in the procedural style it’s worth switching over. Example:$db = new mysqli(…)and$db->prepare("…")The procedural interface is an artifact from the PHP 4 era whenmysqliAPI was introduced and should not be used in new code.mysqliyou should be using parameterized queries andbind_paramto add user data to your query. DO NOT use string interpolation or concatenation to accomplish this because you have created a severe SQL injection bug. NEVER put$_POST,$_GETor any user data directly into a query, it can be very harmful if someone seeks to exploit your mistake.