-1

I want that after submitting a message appears and after three seconds refresh to main page. Need some suggestions to Code this.

Here the main Code with no message:

<!DOCTYPE html>
<html>
<meta http-equiv="content-type" content="text/html" />  
<meta charset="utf-8" />
<?php
require_once("db.inc.php");
?>
<link rel="stylesheet" type="text/css" href="styles2.css" />
</head>
<body>
<?php




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



$stmt = $mysqli->prepare("DELETE FROM artikel WHERE anr=?");
    $stmt->bind_param('i', $_POST['selected_name']);
    $stmt->execute();
    $stmt->close();

if ()

}

?>
<form action="" method="POST">
<p>Artikel:
<?php

$stmt = $mysqli->prepare("SELECT anr, name FROM artikel");
$stmt->execute();
$stmt->bind_result($anr, $name);
echo "<select name='selected_name'><br />";
while ($stmt->fetch ()) {
echo '<option value='.$anr.'>'.$anr.' | '.$name.'</option>'; 

}

echo "</select>"; 





?>
<input type="submit" value="Datensatz löschen" />
</form>
</body>
</html>

For me it's not clear how to Code the if condition in order to let appear the message only after submitting.

Marco
  • 45
  • 8

1 Answers1

0

I have Code it this way:

<?php




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



$stmt = $mysqli->prepare("DELETE FROM artikel WHERE anr=?");
    $stmt->bind_param('i', $_POST['selected_name']);
    $stmt->execute();
    $stmt->close();

   echo "<h2>Artikel gelöscht</h2>";



}
 header ("refresh:3; url=test.php");

?>
 <form action="" method="POST">
<p>Artikel:
 <?php

$stmt = $mysqli->prepare("SELECT anr, name FROM artikel");
 $stmt->execute();
$stmt->bind_result($anr, $name);
echo "<select name='selected_name'><br />";
while ($stmt->fetch()) {
 echo '<option value='.$anr.'>'.$anr.' | '.$name.'</option>';

}


echo "</select>";





 ?>
<input type="submit" name="submit" value="Datensatz löschen" />
</form>
</body>
</html>

But this way the message don't disappear and the page refresh every three seconds, even if i don't submit

Marco
  • 45
  • 8