删除从php / mysql中的组合框中选择的值

时间:2013-04-07 02:51:59

标签: php mysql

我正在尝试从php中删除我的MYSQL数据库中的某个选定值。

[delete.php]

<form name="delete" method="POST" action="d3l3t3d.php">
    <select name="eBox" id="nname" style="width: 290px; height:40px;">
    <?php
    mysql_connect("a","b","") or die("Wrong username or password");
    mysql_select_db("TABLE") or die( "Unable to select database");
    $query = "Select * From list";
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result)) 
    { 
    $name = $row['name']; 
    echo "<option>" . $name . "</option>"; 
    } 
    echo "</select><br/><br/>"
    ?>

[d3l3t3d.php]

<?php
   $namez = $_POST['nname'];
   $name = mysql_real_escape_string($namez);
   mysql_connect("a","b",
   "") or die("Wrong username or password");
   mysql_select_db("TABLE") or die( "Unable to select database");
mysql_query("DELETE FROM list WHERE name='$name'");
?>

我收到以下错误:

  

注意:未定义的索引:C:\ xampp \ htdocs \ folder \ d3l3t3d.php中的nname   在第2行

2 个答案:

答案 0 :(得分:1)

$namez = $_POST['nname'];应为$namez = $_POST['ebox'];

您可以通过姓名选择元素,而不是ID。

答案 1 :(得分:0)

$namez = $_POST['nname'];应为$namez = $_POST['eBox'];

错误:Undefined index: nname in C:\xampp\htdocs\folder\d3l3t3d.php on line 2,表示搜索属性为name = "nname"的元素,当然,该元素不存在。你有name = "eBox"

只是一个小错字:)