这是我的代码:
<?php
ob_start();
session_start();
require 'connection.php';
require 'core.inc.php';
?>
<?php
$take_thread_pid_query = @mysql_query(" select pid from threads ");
$row_take_thread_pid = mysql_fetch_array($take_thread_pid_query);
$pid = $row_take_thread_pid['pid'];
while($row_take_thread_pid = @mysql_fetch_array($take_thread_pid_query))
{
?>
<form action="kill_threads.php" method="POST" >
<label> <?php echo "<br/><br/>thread".$row_take_thread_pid['pid']; ?><input type="submit" value = " <?php echo $row_take_thread_pid['pid'];?> " name = " <?php echo
$row_take_thread_pid['pid']; ?> " /> </label>
<?php }?>
</form>
<?php
$t = "4756";//[4756 is on of the pids in my thread table].this is for testing but doesnt works,it cant find any button with this name.
if ( isset($_POST[$t] ) ) echo "im a killed thread..";
?>
最大的问题是我试图为我创建的每个按钮指定不同的名称,但似乎这不起作用,因为当我试图查看按钮是否设置时['???']
我必须做什么......?
例如
主题1 [按钮1]
主题2 [按钮2]
主题3 [按钮3]
所以如果现在我点击按钮1我想从数据库中删除thread1行。
phpmyadmin就是这样的。
我很复杂..请帮助,提前谢谢。
答案 0 :(得分:0)
您的代码是:
value = " <?php echo $row_take_thread_pid['pid'];?> "
name = " <?php echo $row_take_thread_pid['pid']; ?> "
您在php文本之前和之后放置空格,因此您必须删除空格或代码
答案 1 :(得分:0)
我建议你在表单中使用另一个隐藏的输入元素,而不是使用提交表单,这样你就可以通过传递线程id来使用一个if块来杀死所有线程。
while($row_take_thread_pid = @mysql_fetch_array($take_thread_pid_query))
{
?>
<form action="kill_threads.php" method="POST" >
<label> <?php echo "<br/><br/>thread".$row_take_thread_pid['pid']; ?>
<input type="hidden" name="pid" value="<?php echo $row_take_thread_pid['pid'];?>" />
<input type="submit" value = "Delete" name = "delete_thread" /> </label> <?php }?>
</form>
<?php
$t = "4756";//[4756 is on of the pids in my thread table].this is for testing but doesnt works,it cant find any button with this name.
if ( isset($_POST[$t] ) ) echo "im a killed thread..";
?>
您可能遇到的另一个问题是使用没有名称和ID的多个表单。因此,在表单标记中添加动态数字,如此
<form name="<?php echo $i; ?>" id="<?php echo $i; ?>" action="kill_threads.php" method="POST" >
这里$ i是计数器变量,或者您可以使用$ row_take_thread_pid ['pid']来实现此目的。