English 中文(简体)
每一方 my
原标题:Foreach mysqli delete loop trouble

我非常接近解决我的问题,这就是:

           while ($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
    {
        echo  <tr><td align="left">  .
        $row[ title ] .  </td><td align="left"> 
        . $row[ genre ] .  </td><td align="left"> 
        . $row[ length ] .  </td><td align="left"> 
        . $row[ created ] .  </td><td align="left"> 
        . $row[ views ] .  </td><td align="left">  //. var_dump($row) //dump row value for testing
        .  <input type="checkbox" name="checkbox[]"  value= " .$row[ upload_id ]. " .  /> .  </td> .  </tr> ;



    }
    echo  </table> ; // Close the table

和删除职能:

function submit_delete() {
  if(!is_null($_POST[ delete ]) && !is_null($_POST[ checkbox ])) { //Check to see if a delete command has been submitted.
    //This will dump your checkbox array to your screen if the submit works.
    //You can manually check to see if you re getting the correct array with values
    var_dump($_POST[ checkbox ]);//Comment this out once it s working.
    deleteUploads($id_array);

  }
  else {
    echo "Error: submit_delete called without valid checkbox delete.";var_dump($_POST[ checkbox ]);
  }
}


    function deleteUploads ($id_array) {
      if (count($id_array) <= 0) {   echo "Error: No deletes in id_array!"; var_dump($_POST[ checkbox ]); return; }//bail if its empty
      $delete_success = false;
      foreach ($id_array as &$id) {
        $sql = "DELETE FROM `upload` WHERE `upload_id`=$id AND `owner_id`={$_SESSION[ user_id ]}";
        $result = $mysqli->query($sql) or die(mysqli_error($mysqli));
        if ($result) { $delete_success = true; }
      }

      if($delete_success) {
        header( Location: newwriter_profile.php );
      } else {
        echo "Error: ".mysqli_error();
      }
    }


    //Test deleteUploads (remove once you know the function is working)
    //$test_ids = array();
    //$test_ids[] = 5;//make sure this id is in the db
    //$test_ids[] = 7;//this one too
    submit_delete();
    //deleteUploads($id_array);//should remove ids 10 and 9//

    mysqli_close($dbc);

我已确定<代码>id_array。 核对箱没有获得正确的<代码>_POST值。 蒸汽显示,它有正确的上载胎,然后是I vardump id_array,并显示UNL。 任何帮助都将受到高度赞赏。

CURRENTLY:

        function submit_delete() {
  if(!is_null($_POST[ delete ]) && !is_null($_POST[ checkbox ])) { //Check to see if a delete command has been submitted.
    //This will dump your checkbox array to your screen if the submit works.
    //You can manually check to see if you re getting the correct array with values
   // var_dump($_POST[ checkbox ]);//Comment this out once it s working.
    $id_array = $_POST[ checkbox ];
    var_dump($id_array);
    deleteUploads($id_array);

  }
  else {
    echo "Error: submit_delete called without valid checkbox delete.";//var_dump($_POST[ checkbox ]);
  }
}


function deleteUploads ($id_array) {
  if (count($id_array) <= 0) {   echo "Error: No deletes in id_array!"; return; }//bail if its empty
  $delete_success = false;
  foreach ($id_array as $id) {
    $sql = "DELETE FROM `upload` WHERE `upload_id`=$id AND `owner_id`={$_SESSION[ user_id ]}";
    $result = $mysqli->query($sql) or die(mysqli_error($mysqli));
    if ($result) { $delete_success = true; }
  }

  if($delete_success) {
    header( Location: newwriter_profile.php );
  } else {
    echo "Error: ".mysqli_error();
  }
}

我在提一下“传说”后,正在得到正确选择,但在我提交删除之后,来文方表示,在我结束发言之后,没有人读过(路边和脚步消失)。 目前没有报告错误。

问题回答

看来,在分配价值多少美元时,就没有。 例如,请:

deleteUploads($id_array)

当时没有价值被分配到提款。

有什么价值? 贵国是否需要将美元分配到底线。

我也认为可能有一个错位。

foreach ($id_array as &$id)

我认为,这只是:

foreach ($id_array as $id)




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签