Showing the user an updated page when they add a record

Hello,
I am working on my first database and need to allow it to let users insert a record into the database. After they insert a record the page should be updated with their record added. The following is my current code. I do not know how to show an updated page after they insert their record. Also, this code worked at the beginning and the first four times I tried to enter something through my website I could but now it is not adding anymore. My website is insys.vmhost.psu.edu~vrc112/Databases.html

<?php ini_set('display_errors','On'); error_reporting(E_ALL | E_STRICT); include("includes/connect_info.php"); $connection= mysql_connect($hostname, $mysql_login , $mysql_password); $dbs = mysql_select_db($database, $connection); //Assign the data passed from website to a variable $lastname = mysql_real_escape_string($_POST["lastname"]); $firstname = mysql_real_escape_string($_POST["firstname"]); $assignnum = mysql_real_escape_string($_POST["assignnum"]); $assignscor = mysql_real_escape_string($_POST["assignscor"]); //Testing variables //$firstName = "victoria"; //$lastName = "raish"; //$assignmentNum = "3"; //$score = "5"; $insert=mysql_query("INSERT INTO $vrc112.tgradebook (lastname, firstname, assignnum, assignscor) VALUES ('$lastname', '$firstname', '$assignnum','$assignscor')"); var_dump($insert); var_dump($run_query) mysql_close(); ?>

Firstly, you’re using mysql_query which is now deprecated and will be removed from PHP in a future upgrade. This means that one day, your entire database queries will cease to work so I advise you to get your head in a book and learn PDO or MySqli.

Secondly, the problem is, you’ve updated the database but not refreshed the page. Once you run your query (in PDO/MySQLi) use a header refresh:

[PHP]
header(“Location:yourpage.php”);
[/PHP]

This will send the user back to the page and the updated data should be now visible.

Sponsor our Newsletter | Privacy Policy | Terms of Service