There is a form that sends data to the database. After successful sending a message appears that the data has been added. It is necessary to make sure that after successful submission and addition of data I was not sent to the page with the message, but left on the same page (index.php).

File form.php

<?php require 'connect.php'; mysql_query("SET NAMES utf8"); $id = trim($_REQUEST['id']); $date = trim($_REQUEST['date']); $name = trim($_REQUEST['name']); $phone = trim($_REQUEST['phone']); $address = trim($_REQUEST['address']); $contract_number = trim($_REQUEST['contract_number']); $login = trim($_REQUEST['login']); $credit_amount = trim($_REQUEST['credit_amount']); $months = trim($_REQUEST['months']); $start_amount = trim($_REQUEST['start_amount']); $balance = trim($_REQUEST['balance']); $monthly_payment = trim($_REQUEST['monthly_payment']); $rate = trim($_REQUEST['rate']); $total = trim($_REQUEST['total']); $insert_sql = "INSERT INTO abons_table (id, date, name, phone, address, contract_number, login, credit_amount, months, start_amount, balance, monthly_payment, rate, total)" . "VALUES ('{$id}', '{$date}', '{$name}', '{$phone}', '{$address}', '{$contract_number}', '{$login}', '{$credit_amount}', '{$months}', '{$start_amount}', '{$balance}', '{$monthly_payment}', '{$rate}', '{$total}');"; mysql_query($insert_sql) or die (mysql_error()); //if(isset($_REQUEST['submit'])){} if ($insert_sql=='true') { //header('Location: localhost/bospor/index.php'); echo '<meta http-equiv="refresh" content="0; url=localhost/bospor/index.php">'; } echo "<p>Addition successful</p>"; ?> 

Tried in several ways (at the very end). Did not work out. Please tell me what could be wrong.

It looks like this for now: index.php

And translates me here: enter image description here

    3 answers 3

     echo '<meta http-equiv="refresh" content="0; url=localhost/bospor/index.php">'; 

    Change to:

     header('Location: '.$_SERVER['REQUEST_URI']); 
    • Sends data and goes to a blank form page - luckydutch
    • Do you need to send and leave the form completed? - Urmuz Tagizade
    • Can filled, you can empty. In principle, so far no difference. The main thing is to close the form and I stayed on the index page. Well, or did not even stay, and so that the page is at least just updated after the successful sending. Now I will attach more screenshots to the question. - luckydutch
    • Will be updated. Have you tried? - Urmuz Tagizade
    • Your option? Yes. Nothing changed. I also throws on an empty page form.php. At the end of the question the screenshots show how it all happens to me. - luckydutch

    send the form Ajaksovo if the form is valid and got into the base -> send an answer about the successful completion of sending data to the base. when a success message is received on the client side -> show popup / fading and so on. popup about the success of the operation.

    • I don't really need an answer, but I need to close the form and open the same page on which I was. - luckydutch
    • Well, the beauty of Ajax sending is that you don’t go anywhere at all. And the answer in general terms is needed so that you know that the data on the server side is processed correctly and did something about it if necessary (for example, reset the form fields) - tnorman

    Solved the problem by simply writing without any conditions

     header('Location: ../index.php');