So basically what I have is a simple table inside a form. The goal is to be able to add amount on top of the current amount. At the moment I have a table in my database which consists of 2 Foreign Keys. In this case, the locationcode, and productcode (don't mind the Dutch translation):
if(isset($_POST['submit'])){
// These both give me a undefined index error.
$locatiecode = $_POST["locatiecode"];
$productcode = $_POST["productcode"];
$input = $_POST["input"];
//I suppose the SQL query here below should work once I have fixed the other issues?
$sql2 = "UPDATE aantal SET aantal = aantal + '$input' WHERE locatiecode = $locatiecode AND productcode = productcode";
$result2 = $con->query($sql2);
}
Thats the submit part. Below I have the while loop which selects data from the table, yet again don't mind the Dutch:
<form method="post" action="">
<div style="width: 50%; margin: 0 auto; text-align: center;">
<table class="table">
<thead>
<tr>
<th>Locatiecode</th>
<th>Locatie</th>
<th>Productcode</th>
<th>Product</th>
<th>Fabriek</th>
<th>Inkoopprijs</th>
<th>Verkoopprijs</th>
<th>Aantal</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM locatie INNER JOIN voorraad ON locatie.locatiecode = voorraad.locatiecode INNER JOIN product ON product.productcode = voorraad.productcode";
$result = $con->query($sql);
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<th>" . $row["locatiecode"] . "</th>";
echo "<th>" . $row["locatie"] . "</th>";
echo "<th>" . $row["productcode"] . "</th>";
echo "<th>" . $row["productnaam"] . "</th>";
echo "<th>" . $row["fabrieknaam"] . "</th>";
echo "<th>" . $row["inkoopprijs"] . "</th>";
echo "<th>" . $row["verkoopprijs"] . "</th>";
echo "<th>" . $row["aantal"] . "</th>";
echo "<th><input type='text' name='input' id='aantalinvoer'></th>";
echo "<th><input type='submit' name='submit' id='submit'></th>";
echo "</tr>";
}
?>
</tbody>
</table>
</div>
</form>
So at the moment what happens is, I get a row, with each row an update button (submit button) and an input field. For as now, the input field named, input, is not able to POST. The location and productcode gives me an undefined index when I try to submit.
Does this have something to do with the while loop?
Help would be much appreciated!