I'd like to have an update page where prices of shirts can be updated by admin, by filling in the new price and selecting which shirt's prices will change. However, it doesn't work if I select more than one checkbox.
This is my form:
<form action="" method="post">
<label for= "priceedit">change price:</label>
<input type= "number" name="priceedit"><br>
<input type= "checkbox" name="shirtsort" value="010">
<label for="shirtsort">Casual v neck cropped Shirt</label><br>
<input type= "checkbox" name="shirtsort" value="020">
<label for="shirtsort">Tie Dye Letter Graphic Tee</label><br>
<input type= "checkbox" name="shirtsort" value="030">
<label for="shirtsort">Casual Text Slogan Shirt</label><br>
<input type= "checkbox" name="shirtsort" value="040">
<label for="shirtsort">Neck Frill Trim Ruched Top</label><br>
<input type= "submit" name="verwerkupdate" value="Updaten"> <br>
</form>
</body>
This is my PHP code.
<?php
if (ISSET($_POST['verwerkupdate'])){
if(!empty($_POST['shirtsort'])) {
foreach ($_POST['shirtsort'] as $idedit) ;
}
$priceedit = ($_POST['priceedit']);
echo "<br>".$priceedit."<br>";
echo "".$idedit."";
try {
$db=new PDO("");
$query = $db->prepare("UPDATE kleur SET price= $priceedit WHERE id LIKE '$idedit%'");
if($query->execute()){
echo "Data updated.";
}else{
echo "Error";
}
}catch (PDOException $e) {
die("Error!: " . $e->getMessage());
}
}
?>
Shirts of the same model but different colors have different IDs, which is why I want the query to select shirts that are LIKE "01%", etc. I hope this isn' t the cause of the problem.
". $priceedit. "
"; works. – caroll ann c Jun 02 '21 at 00:11
". $priceedit. "
"' doesn't work. It shouldn't matter but you never know. – CharlesEF Jun 02 '21 at 04:01