This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:web_development:forms:delete [2022/01/24 10:58] mag created |
en:web_development:forms:delete [2023/08/16 09:33] (current) |
||
---|---|---|---|
Line 71: | Line 71: | ||
<li> | <li> | ||
< | < | ||
- | <select name="hero"> | + | <select name="alias"> |
<?php | <?php | ||
// display list of heroes | // display list of heroes | ||
Line 143: | Line 143: | ||
foreach($_POST[' | foreach($_POST[' | ||
if ($movie == ' | if ($movie == ' | ||
- | array_push($args, | + | array_push($args, |
} else { | } else { | ||
error_log($movie); | error_log($movie); | ||
// check if it exists already | // check if it exists already | ||
$mquery = " | $mquery = " | ||
- | $margs | + | $margs |
$rslt = $pdo-> | $rslt = $pdo-> | ||
$rslt-> | $rslt-> | ||
if (!$row = $rslt-> | if (!$row = $rslt-> | ||
- | array_push($args, | + | array_push($args, |
} | } | ||
} | } | ||
Line 201: | Line 201: | ||
* Open the ' | * Open the ' | ||
* Select an entry and click ' | * Select an entry and click ' | ||
- | * This time it won't show at the top of the screen. Instead, it shows a pop-up with | + | * This time it won't show at the top of the screen. Instead, it shows a pop-up |
+ | * You can see the structure of the delete query in the popup. It looks something like this. | ||
+ | < | ||
+ | * We only need to specify the table and the details of the specific record(s) we want deleted. | ||
+ | * We don't have the ' | ||
+ | |||
+ | ==== WHERE IN ==== | ||
+ | * As was the case when we were adding appearances, | ||
+ | * We could identify all the checked movies like < | ||
+ | * We need as many options for < | ||
+ | * Add the following code in the ' | ||
+ | < | ||
+ | $values = str_repeat('?,', | ||
+ | $query = " | ||
+ | * The first line gets the number of movies. | ||
+ | * The second line creates the string of arguments for < | ||
+ | * The third line creates the query string. | ||
+ | * Now we need to create the array of arguments. | ||
+ | < | ||
+ | foreach($_POST[' | ||
+ | array_push($args, | ||
+ | }</ | ||
+ | * First we create the array, then we loop through the movies and add each one to the array. | ||
+ | * Now we send the query to the database, with a check on whether it worked or not. | ||
+ | < | ||
+ | if ($rslt-> | ||
+ | $message = " | ||
+ | } else { | ||
+ | $message = "There was a problem deleting $movies appearances"; | ||
+ | }</ | ||
+ | * Save and upload the code and check that everything works as expected. | ||
+ | |||
+ | [[en: |