0

这是我的代码:

<?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 是这样工作的。

我很复杂..请帮助,提前谢谢。

4

2 回答 2

0

你的代码是:

value = " <?php echo $row_take_thread_pid['pid'];?> " 
name = " <?php echo $row_take_thread_pid['pid'];  ?> "

您在 php 文本之前和之后放置空格,因此您必须删除空格或为它们编码

于 2013-09-18T10:29:10.463 回答
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'] 。

于 2013-09-18T10:38:15.117 回答