gpt4 book ai didi

php - 传递 php 变量

转载 作者:行者123 更新时间:2023-11-29 02:17:06 27 4
gpt4 key购买 nike

我正在创建一个用于管理数据库的用户界面。每个条目都有两个单选按钮,一个用于验证(以及随后通过电子邮件发送给有关当局),一个用于删除条目。下面给出代码,粗体部分是与此功能相关的部分。几个问题:1)没有 form 属性是否可以这样做?如果可以,我该怎么做?

2) 通过 form 属性,我使用 'handle.php' 删除每个条目。 “handle.php”中的语法包括这一行

$sql="DELETE FROM rti WHERE ID=x"; //x here is the ID number to delete.

现在,如何从我的界面传递 ID 的值,以便上面的代码行删除与按下的按钮对应的条目?

<html>
<head>
<style>
* {
margin: 0px;
padding: 0px;
}

div.topbar {
position: relative;
background-color: black;
height: 45px;
text-align: center;
font-family: Calibri;
font-size: 30px;
padding-top: 10px;
}

div.topbar img {
position: absolute;
left: 10px;
top: 0px;
}

div.topbar span {
color: white;
}

div.container {
background-color: #a5a5a5;
width: 100%;
height: 100%;
color: white;
}

div.data {
padding: 20px;
}

table {
background-color: #b1b1b1;
border-collapse: collapse;
}


th, td {
text-align: center;
border: solid 1px black;
margin: 0px;
}

th.one {
width: 50px;
}

th.two{
width: 150px;
}

th.three {
width: 75px;
}

th.four {
width: 200px;
}

div.validation {
background-color: #b5b5b5;
width: 200px;
height: 100%;
position: relative;
left: 1100px;
bottom: 300%;
text-align: center;
border-left: solid 1px black;
}
</style>
</head>
<body>
<div class = "topbar"><img src="logo.png"><span>RTI DATABASE</span></div>
<div class = "container">
<div class ="data">
<?php
$servername="localhost";
$username="root";
$password='';
$conn=mysql_connect($servername, $username, $password) or die ("Error connecting to mysql server: ".mysql_error());
$dbname = 'bsp';
mysql_select_db($dbname, $conn) or die ("Error selecting specified database on mysql server: ".mysql_error());
$sql="SELECT * FROM rti";
$result=mysql_query($sql) or die ("Query to get data from firsttable failed: ".mysql_error());
echo "<table>";
echo "<tr>";
echo '<th class="one">ID</th>
<th class="two">Name</th>
<th class="three">Board</th>
<th class="four">Query</th>
<th class="five">Validate</th>
<th class="six">Delete</th>
<th class="seven">Submit</th>';

echo "</tr>";
while ($row=mysql_fetch_array($result)) {
$id=$row["ID"];
$name=$row["name"];
$board=$row["board"];
$query=$row["query"];
echo "<tr>";
echo "<td>$id</td>
<td>$name</td>
<td>$board</td>
<td>$query</td>
**<form action='handle.php' method='POST'>
<td><input type='radio' name='option' value='validate'></td>
<td><input type='radio' name='option' value='delete'></td>
<td><input type='submit' value='Submit' name='submit'>
</form></td>";
echo "</tr>";**
}
echo "</table><br>";
?>
</div>
</div>
</body>
</html>

最佳答案

**<form action='handle.php' method='POST'><td><input type='radio' name='option' value='validate'></td>
<td><input type='radio' name='option' value='delete'>
<input type='hidden' name="id" value='".$id."'>
</td>
<td><input type='submit' value='Submit' name='submit'></form></td>";

在 handle.php 中:

$id = $_POST['id'];

关于php - 传递 php 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37850495/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com