简体   繁体   中英

Return to Home page after Delete function PHP MYSQL JAVASCRIPT

Sorry I'm Beginner, I would like to ask if how to go back from Home page or Specific Page after Delete.php it was only a blank page.

EDIT

It's look like this after the delete was succesful.

在此处输入图片说明

Here is my code:

delete.php

<?php
    session_start();
    include_once 'dbconnect.php';
    $id = $_GET['id'];
    $sql = mysql_query("DELETE FROM accounts where user_id='$id'");

    if ($sql > 0) {
?>
    <script> alert('Record has been successfully deleted'); </script>
<?php
    } else {
?>
    <script> alert('Database Error!'); </script>
<?php
    }
?>

Here is where I call the delete.php function:

<td>
    <a href="delete.php?id=<?php echo $row['user_id']; ?>" onclick="return confirm('Are you sure?');">
        Delete
    </a>
</td>

You can use

header('Location:any_page.php');
exit;

in delete.php

Use javascript window.location

<?php
   session_start();
   include_once 'dbconnect.php';

   $id=$_GET['id'];
   $sql=mysql_query("DELETE FROM accounts where user_id='$id'");

   if($sql > 0) {
   ?>

  <script> alert('Record has been successfully deleted'); 
window.location.replace("page name");

</script>

  <?php
 } else{ 
  ?>

  <script> alert('Database Error!'); 
window.location.replace("page name");
 </script>

 <?php
  }
  ?>

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