-1

I am struggling here a little. I have following code which is working. However at the moment i get messege "Connected successfully".

What i would like is when data is sent to mysql database, to go back to "xxx.html" which is my site where user input data.

Thanks in advance!

$conn = new mysqli($servername, $username, $password,$dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$sql = "INSERT INTO smart_zaposleni (ime, priimek, dopust, kontakt)
VALUES
('$_POST[ime]','$_POST[priimek]','$_POST[dopust]','$_POST[kontakt]')";

if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}$conn->close();
Rok Ivartnik
  • 137
  • 5
  • 17
  • 1
    add `header('Location: xxx.html'); exit;` after the `echo "New record created successfully";` – RiggsFolly Aug 10 '16 at 18:35
  • 1
    The user will not be able to see that message, but will be redirected immediately. There is not wait, the lines will be executed in order but there is no time for the user to see the echo. But the answer is header('Location: xxx.html'); – Sam Battat Aug 10 '16 at 18:36

1 Answers1

1
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
header( "refresh:10;url=whereever.php" ); 
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}$conn->close();
AJ Riley
  • 196
  • 1
  • 10