Edmhar Edmhar - 7 months ago 26
PHP Question

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.

enter image description here

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>

Answer

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
  }
  ?>