Jump to content

Redirecting page after form post method


myristate

Recommended Posts

Hi there, I wrote a pretty simple html form that inputs data into my database. I've included a truncated version of it, There are a lot more fields. Basically when i hit the submit it processes input.php but after its been successful the page is still at input.php in the browser Is there anyway to take the page back to the page i was using to input data

<form action="insert.php" method="post">
  <p>Adornment Name: <br>
    <input type="text" name="name">
    <br>
    <br>
    Quality: <br>
    <select name="quality">
      <option value="Other">Other Not Listed</option>
      <option value="Superior">Superior</option>
      <option value="Greater">Greater</option>
      <option value="Lesser">Lesser</option>
      <option value="Raid">Raid</option>
      <option value="Faction">Faction</option>
    </select>
</form>

include 'db_connect.php';

$sql="INSERT INTO $db_table (name, quality)
VALUES
(
		'$_POST[name]',  
	 '$_POST[quality]')";



if (!mysql_query($sql,$db))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

mysql_close($db)
?>

 

Link to comment
Share on other sites

 

Assuming you want the user to see the "1 record added" message, put a Back button at the end of the code to return to the input form -

 


<head>
<script type="text/javascript">
function goBack()
{
window.history.back()
}
</script>
</head>


<input type="button" value="Back" onclick="goBack()" />

 

Link to comment
Share on other sites

Ok I've been up since 5am but why do you have redirect in your title?

 

Aren't you wanting it to stay on the same page/file?

 

To me something is missing, from what I see it should stay on insert.php after you have inserted your info. You have something redirecting your page.

 

check that out then maybe use header() if all else fails

 

header("Location: insert.php");

exit();

mysql_close($db)

?>

 

And "echo "1 record added";" doesn't mean one record was added, it just means the script ran. I use a simple sql query that diplays the last record added to let me know I the info entered and that it was entered correctly.

Link to comment
Share on other sites

The 1 record added was actually part of a code snippet i had used that i never removed its not actually meant to be there. I guess i dint explain it very well. rather than having the page go to insert.php on submit to process it i was hoping there was a way to keep it on add.php (even though it still needs to process insert.php)I did think about using the get method instead of put but i have long variables and some things i don't want visible in the url path. I had read about the header redirect thing, However wouldn't that redirect before it processes the php in the page

Link to comment
Share on other sites

 

You should anticipate input or db errors - missing fields, invalid inputs, server errors, etc. - and have insert.php echo error messages so the user knows the update failed and why.  If the script just dies when an error occurs, it will leave the user hanging and they won't know how to continue.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.