PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
if (isset($_POST['Addrec'])) // the addition function above was executed to add an item
{
$Tvar = "I"; // assume an income item
if (isset($_POST['Cex_x']) || isset($_POST['Lex_x'])) $Tvar = "E"; // adding an expense item
if (isset($_POST['Cmi_x']) || isset($_POST['Lmi_x'])) $Tvar = "M"; // adding an mileage item
$Cvar = "N";
if (isset($_POST['Cin_x']) || isset($_POST['Cex_x']) || isset($_POST['Cmi_x'])) $Cvar = "Y";
$Query = "INSERT INTO Exprec (Tref,Type,Calc) VALUES (" . $_POST['Addrec'] . ",'$Tvar','$Cvar')";
mysql_query($Query, $Link); // add the detail and re-display the time card
$Vrec = $_POST['Addrec']; // view the item with the added record
unset($_POST); // to allow refresh
}
if ($Vrec) // selected an individual timecard for editing
{
// code here to display the records
}
?>
For a number of reasons, a "refresh" of the page is very common, and when that happens a duplicate record is inserted into the database. Unsetting the $_POST array should solve that, but it doesn't. How can I allow a refresh of the page without a duplicate database record being created?
Rite behind it, the explanation says "allows for refresh".
Have you tried a exit statement rite after that? (i noticed you had some code that needs to go after this call, so perhaps that wont work, but it will at least stop the refresh query.
So, in short, its posting, and than the next line (if vrec) is going back and saying "yes, it posted"...this creates the refresh i guess.....just a different way of refreshing data i guess. A person could just have another .php scipt/page that shows the results, and eliminate that all together..
That's a function call that executes a MySQL database query.
I put the code that adds the new detail into a seperate script and used a header to return to this script (which contains revision code as well as display code.)