【发布时间】:2011-05-23 14:42:18
【问题描述】:
我正在尝试设置一个带有 2 个按钮的表单 - 在页面 delete.php 上运行的“DELETE”和在 edit.php 上运行的“EDIT”。
所以我需要根据他们点击的按钮采取不同的操作...
这是我的代码。
$con = mysql_connect("localhost","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$result = mysql_query("SELECT * FROM myTable");
// Need to change the action depending on what button is clicked
echo "<form name='wer' id='wer' action='delete.php' method='post' >";
echo "<table border='1'>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['page_title'] . "</td>";
echo "<td><input type='radio' name='test1' value='" . $row['id'] . "' /></td>";
echo "</tr>";
}
echo "<tr>";
echo "<td> </td>";
echo "<td> </td>";
echo "<td><input type='submit' name='delete' value='Delete' /> <input type='submit' name='edit' value='Edit' /></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
mysql_close($con);
【问题讨论】:
标签: php forms form-submit