added priority

This commit is contained in:
2023-01-18 21:09:06 +01:00
parent 05f11a18cd
commit 4e30e3a439
4 changed files with 92 additions and 11 deletions

View File

@@ -10,6 +10,7 @@ $ItemPrice = $_POST['ItemPrice'];
$ItemLink = $_POST['ItemLink'];
$ItemImage = $_POST['ItemImage'];
$ListID = $_POST['ItemListID'];
$nextPriority = 0;
#--- check if the provided Link is a valid URL
@@ -42,13 +43,20 @@ if ($conn->connect_error) {
die('Connection failed: ' . $conn->connect_error);
}
$stmt = $conn->prepare('INSERT INTO whishes (title, description, link, image, price, whislist) VALUES (?, ?, ?, ?, ?, ?)');
$stmt = 'SELECT MAX( priority ) AS maxprio FROM whishes WHERE whislist = ' . $ListID . ';';
$result = $conn->query($stmt);
if (false === $stmt) {
die('prepare() failed: ' . htmlspecialchars($mysqli->error));
while ($row = mysqli_fetch_array($result)) {
$nextPriority = $row['maxprio'] + 1;
}
$rc = $stmt->bind_param('ssssii', $ItemTitle, $ItemDescription, $ItemLink, $imageLocalLink, $ItemPriceCents, $ListID);
$stmt = $conn->prepare('INSERT INTO whishes (title, description, link, image, price, whislist, priority) VALUES (?, ?, ?, ?, ?, ?, ?)');
if (false === $stmt) {
die('prepare() failed: ' . htmlspecialchars($conn->error));
}
$rc = $stmt->bind_param('ssssiii', $ItemTitle, $ItemDescription, $ItemLink, $imageLocalLink, $ItemPriceCents, $ListID, $nextPriority);
if (false === $rc) {
die('bind_param() failed: ' . htmlspecialchars($stmt->error));
}