Reputation: 91
In a select field i have stored three different values of an array . The $listabrand['0'] contains the ID of the record.
<select name='brands_list'>
<option value="0">Select the Brand</option>
<?php
while ($listabrand=mysqli_fetch_array($brands)){
echo '<option value="'.$listabrand['0'].','.$listabrand['1'].','.$listabrand['2'].'">
'.$listabrand['1'].'</option>';
}?>
</select>
I am implementing the DELETE Record function, selecting the value in the field 'brands_list' but at point it's difficult to me declare the ID into a variable since the brands_list field contains 3 different array values.
I put this but of course can't work because it doesn't know which value have to capture and it should be the $listabrand['0'].
$mod_id = mysqli_real_escape_string ($conn, $_REQUEST['brands_list']);
I embed the full php, it could be helpful
<?php
require '../sys/conn.php';
$mod_id = mysqli_real_escape_string ($conn, $_REQUEST['brands_list']);
if (isset($_GET['delete_brand'])){
$delquery = mysqli_query($conn,"DELETE FROM mg_terms where term_id= $mod_id");
$delquery1 = mysqli_query($conn,"DELETE FROM mg_term_taxonomy where term_id= $mod_id");
$delquery2 = mysqli_query($conn,"DELETE FROM mg_termmeta where term_id= $mod_id");
header('Location: ../pages/success.html');
}
else{header('Location: ../pages/error.html');
}
mysqli_close($conn);
?>
The question is, how to select the ID in the above condition. Suggestions?
Upvotes: 0
Views: 26
Reputation: 13635
Since you're building a comma separated string, you need to break it apart again.
There are a couple of different ways to do this.
If you just want the first part, the id, you can use strtok():
$id = strtok($_REQUEST['brands_list'], ',');
If you want all the parts, you can use explode() and list():
list($id, $part2, $part3) = explode(',', $_REQUEST['brands_list']);
Upvotes: 1