0

嗨朋友请告诉我我哪里错了,即使更新查询执行成功,数据库仍然没有变化谢谢

这是表单代码

echo'<form action="processor.php" method="post" id ="post_form">';
echo '<input type="hidden" name= "status" id="status" value="">';
$upload_arr=array("1");
foreach($upload_arr as $upload_id)
{
    echo '<input type="button" name="accept-<?=$upload_id?>"   value="accept"             onclick="submit_this(this.name)"/><br>';
    echo    '<input type="button" name="reject-<?=$upload_id?>"  value="reject"  onclick="submit_this(this.name)"/><br>';
    echo    '<input type="button" name="saccept-<?=$upload_id?>"   value="saccept" onclick="submit_this(this.name)"/><br>';
    echo    '<input type="button" name="sreject-<?=$upload_id?>"   value="sreject"       onclick="submit_this(this.name)"/><br>';
 }
echo '</form>';

注意:这里我使用了 $upload_id 一个 php 变量,它具有 row[upload id] 即它就像第一个图像的接受 1、reject1、saccept1 和 sreject1 和第二个图像它是 accept2 reject2 等等

现在是processor.php的代码

$status_pass = isset($_POST['status'])?$_POST['status']:NULL;
if(!empty($status_pass)){
$status_arr = explode('-', $status_pass);
$action  = $status_arr[0];
$upload_id = $status_arr[1];

if($action == 'accept'){
    $status = 1;
}
if($action == 'reject'){
    $status = 2;
}
if($action == 'saccept'){
    $status = 3;
}
if($action == 'sreject'){
    $status = 4;
}
echo $status;
$sql="UPDATE upload SET status='$status' where upload_id = '$upload_id' ";
echo "update success";
 $result = mysql_query("$sql") or die("Invalid query: " . mysql_error());

}
4

4 回答 4

1

以你的形式

<form action="processor.php" method="post" id ='post_form'>
  <input type="hidden" name= "status" id="status" value="">
  <?php
    foreach($upload_arr as $upload_id){
  ?>
      <input type="button" name="accept-<?=$upload_id?>"   value="accept" onclick='submit_this(this.name);'/><br>
      <input type="button" name="reject-<?=$upload_id?>"  value="reject" onclick='submit_this(this.name);'/><br>
      <input type="button" name="saccept-<?=$upload_id?>"   value="saccept" onclick='submit_this(this.name);'/><br>
      <input type="button" name="sreject-<?=$upload_id?>"   value="sreject" onclick='submit_this(this.name);'/><br>
  <?php
    }
  ?>
</form>
<script>
function submit_this(name){
    document.getElementById('status').value = name;
    document.getElementById('post_form').submit();
}
</script>

在你的 php 文件中

<?php
$status_pass = isset($_POST['status'])?$_POST['status']:NULL;

if(!empty($status_pass)){
    $status_arr = explode('-', $status_pass);
    $action  = $status_arr[0];
    $upload_id = $status_arr[1];

    if($action == 'accept'){
        $status = 1;
    }
    if($action == 'reject'){
        $status = 2;
    }
    if($action == 'saccept'){
        $status = 3;
    }
    if($action == 'sreject'){
        $status = 4;
    }

    $sql="UPDATE upload SET status='$status' where upload_id = '$upload_id' ";
    //execute sql here
}


?>
于 2013-10-08T07:46:30.203 回答
0

你能把$_POST["accept'.$upload_id.'"]这个换成 $_POST["accept".$upload_id]

于 2013-10-08T06:59:13.677 回答
0

你的代码有一些问题

第一的

如果要多个提交表单,类型应该是按钮,可以使用javascript来控制提交表单,并且在提交之前,您还可以将一些值传递给隐藏输入字段,例如,您可以设置隐藏输入值= “接受'.$upload_id.'”

第二

在你的 php 文件中,

$sql="更新上传设置状态='1'";

没有 where 条件,当然,这会更新你的所有记录。

于 2013-10-08T07:11:38.290 回答
0

不要为 $upload_id 输入标签使用 '' 引号,它会正常工作

于 2013-10-08T07:02:37.610 回答