简体   繁体   English

提交按钮未设置

[英]Submit button won't set

We can't get the delete "submit" button to set, otherwise it would work, we can't understand what part of the code is wrong. 我们无法设置删除“提交”按钮,否则它将起作用,我们无法理解代码的哪一部分是错误的。

Imagine a table row with a few columns, which contain data from a database in the td's 想象一个表行有几列,其中包含来自td的数据库的数据

// While it goes through each row (which is selected from another SQL query above, but I won't bother pasting that)
while ($row = mysql_fetch_array($result)) {
// Variable is equal to the Request ID (e.g. 10)
$numb = $row['ReqID']; 

// Echo's the table td rows with each column name in the database
echo "<tr>";
echo "<td class='req' align='center'>".$row['ReqID']."</td>";
echo "<td class='req' align='center'>".$row['ModTitle']."</td>"; 
echo "<td class='req' align='center'>".$row['BuildingID']."</td>";
echo "<td class='req' align='center'>".$row['RoomID']."</td>";
echo "<td class='req' align='center'>".$row['Priority']."</td>";
echo "<td class='req' align='center'>".$row['W1']."</td>";
echo "<td class='req' align='center'>".$row['P1']."</td>";
// Delete button also in a td row, uses the variable "$numb" to set the button name
echo "<td class='req' align='center'><input type='submit' name='{$numb}' value='Delete'></td>";
echo "</tr>";

// If the delete button is pressed, delete the row (this query works, we tested it, but the button just doesn't set so it doesn't activate the SQL command)
if (isset($_POST[$numb])) {
$result2 = mysql_query("DELETE FROM Request WHERE ReqID = {$numb} LIMIT 1", $connection);
}
}

Use a hidden input to store the value: 使用hidden输入来存储值:

somewhere above... 上方某处...

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

a little bit below... 下面一点...

echo "<td class='req' align='center'><input type='submit' name='submit' value='Delete'>";
echo '<input name="hello" type="hidden" value="$numb" /></td>';
...
$number = mysql_real_escape_string($_POST["hello"]);
$result2 = mysql_query("DELETE FROM Request WHERE ReqID = ".$number." LIMIT 1", $connection);

at the bottom: 在底部:

</form>

Note: 注意:

Your approach isn't safe enough. 您的方法不够安全。 I can easily edit the DOM and give another value to the hidden field (or another name for the button) causing to delete other elements from the database. 我可以轻松地编辑DOM并将其他值赋予隐藏字段(或按钮的其他名称),从而从数据库中删除其他元素。 Keep in mind this. 请记住这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM