Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php删除函数。捕获数组中包含并存储在选择字段中的ID_Php_Arrays_Variables - Fatal编程技术网

Php删除函数。捕获数组中包含并存储在选择字段中的ID

Php删除函数。捕获数组中包含并存储在选择字段中的ID,php,arrays,variables,Php,Arrays,Variables,在选择字段中,我存储了一个数组的三个不同值。 $listabrand['0']包含记录的ID <select name='brands_list'> <option value="0">Select the Brand</option> <?php while ($listabrand=mysqli_fetch_array($brands)){ echo '<option value="'.$listabrand['0'].','.$listab

在选择字段中,我存储了一个数组的三个不同值。 $listabrand['0']包含记录的ID

<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>
我嵌入了完整的php,这可能会有帮助

<?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);
?>


问题是,如何在上述条件下选择ID。建议?

由于要构建逗号分隔的字符串,因此需要再次将其拆分

有几种不同的方法可以做到这一点

如果您只需要第一部分,即id,您可以使用:

如果需要所有零件,可以使用和:


如果只需要字符串中的第一个值,可以使用。示例:
$id=strtok($需求['brands\u list'],',')。您还应该使用而不是连接查询。即使是
mysqli\u real\u escape\u string()。我将实施安全步骤作为第二步。谢谢,效果很好。我将添加它作为答案,以便您可以接受它
<?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);
?>
$id = strtok($_REQUEST['brands_list'], ',');
list($id, $part2, $part3) = explode(',', $_REQUEST['brands_list']);