Redirect to newly added record
Posted: Mon Dec 23, 2013 1:25 pm
Greets..
I have a page with an add form. This form is adding to a table with a unique KEY "ID". Once I add the record I want to go to this record. The code below is how I'm doing it now. Just wanted to know if there is a better way.
I have a page with an add form. This form is adding to a table with a unique KEY "ID". Once I add the record I want to go to this record. The code below is how I'm doing it now. Just wanted to know if there is a better way.
Code: Select all
<?php
mysql_query("INSERT INTO ".$targetapp." (".trim($fieldnames, ",").") VALUES(".trim($fielddata, ",").")");
$SQL = "SELECT ID FROM ".$targetapp." ORDER BY ID DESC LIMIT 1";
$result = mysql_query($SQL);
while($row = mysql_fetch_array($result)){
$lastID = $row['ID'];
}
mysql_close($result);
echo $lastID;
?><meta http-equiv="refresh" content="0;URL='start.php?id=<?php echo $lastID ?>&con=det&app=<?php echo $targetapp ?>'" /><?php
?>