表单不传递变量php

时间:2017-05-17 11:01:52

标签: php html forms

我已经制作了一个简单的表格来删除表格中的条目。当我单击提交按钮时,我的变量不会填充。有人可以建议为什么?这是html代码:

<tr class="tr">
   <td class="td">2</td>
   <td class="td">01/05/2017</td>
   <td class="td">1152</td>
   <td class="td">1270</td>
   <td class="td">1125</td>
   <td class="td">855</td>
   <td class="td">1078</td>
   <td class="td">865</td>
   <td class="td">1730</td>
   <td class="td">1255</td>
   <td class="td">
      <form action="delete.php" "method="post">
         <input type="hidden" value="2" name="id">
         <input type="hidden" value="zjl1nl_asia" name="region">
         <input type="submit" value="Delete" class="delete_button">
      </form>
   </td>
</tr>

和接收php

<?php
function secure($var){
    $var = stripslashes($var);
    $var = strip_tags($var);
    $var = htmlentities($var);
    return $var;
}
    //Connect to database
    $hn = "localhost";
    $db = "XXXX";
    $un = "XXXX";
    $pw = "XXXX";

    $conn = new mysqli($hn, $un, $pw, $db);
    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
    }

$id = secure($_POST['id']);
$region = secure($_POST['region']);

echo "<p>id: $id<br>region: $region</p>";

$query = "DELETE FROM $region WHERE id=$id";
echo $query."<br>";
$result = $conn -> query($query);
if(!$result) die ("Error: ".$conn->error);

$conn->close(); 

?>

当我将变量回显到屏幕时,它们没有显示任何值。查看地址栏但我可以看到例如: www.example.com/add/delete.php?id=6&region=zjl1nl_asia

有谁知道为什么变量没有填充?

1 个答案:

答案 0 :(得分:3)

此代码行中存在语法错误。

<form action="delete.php" "method="post">

将其替换为

<form action="delete.php" method="post">

现在它应该可以正常工作。