connect_error) { die('Connection failed: ' . $conn->connect_error); } $stmt = 'SELECT MAX( priority ) AS maxprio FROM whishes WHERE whislist = ' . $ListID . ';'; $result = $conn->query($stmt); while ($row = mysqli_fetch_array($result)) { $nextPriority = $row['maxprio'] + 1; } $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)); } $rc = $stmt->execute(); if (false === $rc) { die('execute() failed: ' . htmlspecialchars($stmt->error)); } $stmt->close(); $conn->close(); header('Location: ' . $_SERVER['HTTP_REFERER']);