After learning how to setup a environment with html, js, ajax, php and mysql I'm able to insert single instances into a table.
I'm trying to get it working with multiple entries into the table for quite a while now. I was reading several documentation pages and recommendations on here but couldn't really figure out what I'm missing.
To clarify: What I'm trying to do is to insert 2 of the same entity. I input SafetyStock
and LotSize
of the Material Pack
thereupon, insert another Material named PET with different
There is no problem with getting the variables from ajax but i don't get the $stmt->bind_param
line. What do I have to write there to make the code running?
I tried to just have two lines of stmt
binding, but then it only wrote the last entry into the database. Another thing I did was execute the stmt
and then overwrite the variables and then do execute again, wasn't working as well.
my actual insert.php:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "scm";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// prepare and bind settingssupplychaincomponents
$stmt = $conn->prepare("INSERT INTO test1 (settingsSupplyChainComponentsId, settingsSupplyChainId, componentId, safetyStockW, lotSizeW)
VALUES (?, ?, ?, ?, ?), (?, ?, ?, ?, ?)");
$stmt->bind_param("iiiii", $settingsSupplyChainComponentsId, $settingsSupplyChainId, $pack, $sspack, $lspack); //Pack
// set parameters for components
$settingsSupplyChainComponentsId = '';
$settingsSupplyChainId = $_POST['ssci'];
// set parameters for pack
$pack = 1;
$sspack = $_POST['sspack'];
$lspack = $_POST['lspack'];
// set parameters for PET
$pet = 2;
$sspet = $_POST['sspet'];
$lspet = $_POST['lspet'];
$values = array();
$stmt->execute($values);
echo "New records created successfully";
$stmt->close();
$conn->close();
?>