简体   繁体   中英

Refresh page after submit form

I've created a gallery management. I printed the image thumbnails with a While loop. Can I select the photos to be deleted by a checkbox and then submit the form. when I send the form, the page refreshes, she run images unlink(), delete row query, but I still see the printed row with 404 (Not Found) for the image. If i Refresh another one, works!

The code:

<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

//while loop

</form>

<?php


if (isset($_POST['delete'])) {


    $delete = $_POST['select'];

foreach ($delete as $id => $val) {

    $query="SELECT foto FROM gallery WHERE id = '$val'";
    $result1= mysql_query($query);
     while($row = mysql_fetch_assoc($result1)) {
        unlink($output_dir . $row[foto]); 
    }

    $query="DELETE FROM gallery WHERE id = '$val'";
    $result2= mysql_query($query) or die (mysql_error()); 



}



}

sOLVED. EDIT:

if (isset($_POST['delete'])) {


    $delete = $_POST['select'];

foreach ($delete as $id => $val) {

    $query="SELECT foto FROM gallery WHERE id = '$val'";
    $result1= mysql_query($query);
     while($row = mysql_fetch_assoc($result1)) {
        unlink($output_dir . $row[foto]); 
    }

    $query="DELETE FROM gallery WHERE id = '$val'";
    $result2= mysql_query($query) or die (mysql_error()); 



}



}

 <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

    //while loop

    </form>

您必须在php代码之后编写表格

You should run the PHP code before the HTML part.

Try this:

<?php
if (isset($_POST['delete'])) {
  $delete = $_POST['select'];
  foreach ($delete as $id => $val) {
    $query="SELECT foto FROM gallery WHERE id = '$val'";
    $result1= mysql_query($query);
    while($row = mysql_fetch_assoc($result1)) {
      unlink($output_dir . $row[foto]); 
    }

    $query="DELETE FROM gallery WHERE id = '$val'";
    $result2= mysql_query($query) or die (mysql_error()); 
  }
}
?>

<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  //while loop
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM