I am trying to add items to an array each time I submit the form above it.
The first 2 items you see in the screenshots are hardcored for the example.
The third item which is a long code is the item I pull from my database and then push it into the array.
My problem is that every time I submit the form to add a new item into the array the new item simply overwrites the previous one as you can see in the screenshots below.
insertProduct.php
$inserted_product_code = $_POST["code"];
$sql = "SELECT products.code FROM products WHERE products.code = '$inserted_product_code'";
if($result = mysqli_query($link, $sql)){
while ($row = mysqli_fetch_assoc($result)){
array_push($inserted_products, $row['code']) ;
}
}
echo print_r($inserted_products);
createTable.php
$inserted_products = array("Entry 1","Entry 2");
<form method="POST" action="">
<input type="text" name="code" placeholder="Your Input" required />
<button type="submit" name="insertProduct"> Submit </button>
</form>
if (isset($_POST['insertProduct'])) {
include 'insertProduct.php';
}