Redirect to new record

Hi folks, hope you may be able to provide some help or an insight here as to how I would go about building a code that does the following: Basically, I’ve built this database, and when the user fills out the form and hits the submit button, I need the page to instantly redirect to an output page containing the data they just entered.

I’ve tried using the PHP header function, but I can’t seem to get that to redirect, someone also recommended the function, but that’s already in use, so I thought I’d post here at a forum specilaised in this.

Here’s the code I’ve been using to try and redirect:

[code]header (“Location: result.php?id=FIELD_NAME”);


(Where FIELD_NAME is “assetid” )

Does anyone know what I could do to try and get this working?

Cheers. :)

Basically what you’re looking for is form functionality. Say you have a page form.php and result.php. Form.php would look like this:



Result.php would look like this:

<?php $id = intval(trim($_POST['id'])); $sql = "SELECT * FROM mytable WHERE id = ".$id; $result = mysql_query($sql); while ($data = mysql_fetch_assoc($result)) { print_r($data); }

Is that what you’re looking for?

Hmm possibly, but will it work if there are already two

action="" identifiers?
In my form, I’ve already got

<form method="post" name="form1" action="<?php echo $editFormAction; ?>"> so would adding action=“result.php” and action=“post” be applicable ?

No, you can only have one action attribute in a form element. What is it currently used for?

The attribute is currently used in the following manner:

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">

Your code is a litte confusing. So currently the editFormAction var is set to a page that is the resulting action correct?
We may need more of the code in order to get help (maybe just the form).
From what I’ve seen so far I think your easiest option is to change $editFormAction page (remember you have access to the POST form data there) outputting the entered user data from there as well as whatever function it is already covering.

The code carries out the “Edit Form Action” coding at the top of the following:

$form = $_POST[‘form1’];
$editFormAction = $_SERVER[‘PHP_SELF’];
if (isset($_SERVER[‘QUERY_STRING’])) {
$editFormAction .= “?” . htmlentities($_SERVER[‘QUERY_STRING’]);
if ((isset($_POST[“MM_insert”])) && ($_POST[“MM_insert”] == “form1”)) {

mysql_select_db($database_mysql, $mysql);
$Result1 = mysql_query(“INSERT INTO assetman.assetsreg (assetno, assetname, asserialno, assetype, location, supp, pcost, sprice, taspref, replaceval, ifcombined, custodian, extintcalibr, calicertloc, ukascalibr, mantype, manstore, manloc, added, age, comments, description, day, month, year, sday, smonth, syear, dept) VALUES (’$_POST[assetno]’,’$_POST[assetname]’,’$_POST[asserialno]’,’$_POST[assetype]’,’$_POST[location]’,’$_POST[supp]’,’$_POST[pcost]’,’$_POST[sprice]’,’$_POST[taspref]’,’$_POST[replaceval]’,’$_POST[ifcombined]’,’$_POST[custodian]’,’$_POST[extintcalibr]’,’$_POST[calicertloc]’,’$_POST[ukascalibr]’,’$_POST[mantype]’,’$_POST[manstore]’,’$_POST[manloc]’,’$_POST[added]’,’$_POST[age]’,’$_POST[comments]’,’$_POST[description]’,’$_POST[day]’,’$_POST[month]’,’$_POST[year]’,’$_POST[sday]’,’$_POST[smonth]’,’$_POST[syear]’,’$_POST[dept]’)”) or die(mysql_error());

header (“Location:”);

Gordon, here is some sample form coding, that you requested; I didn’t notice what you mentioned. :P

<tr valign="baseline"> <td class="cellsize" nowrap><p class="ltext">asset number:</p></td> <td width="204"><input type="text" name="assetno" value="" size="34"></td> </tr> <tr valign="baseline"> <td nowrap class="cellsize"><p class="ltext">description:</p></td> <td><input type="text" name="description" value="" size="34"></td> </tr> <tr valign="baseline"> <td nowrap class="cellsize"><p class="ltext">make/model:</p></td> <td><input type="text" name="assetname" value="" size="34"></td> </tr> <tr valign="baseline"> <td nowrap class="cellsize"><p class="ltext">serial number:</p></td> <td><input type="text" name="asserialno" value="" size="34"></td> </tr> <input type="submit" value="Add New Item"> &nbsp;&nbsp;&nbsp;&nbsp; <input type="reset" value="Clear">


Sponsor our Newsletter | Privacy Policy | Terms of Service