Forum Moderators: coopster

Message Too Old, No Replies

HTML/PHP Form and saving to Database

Posting data to another page and saving to a Database using a HTML/PHP Form

         

ted77

10:41 am on Dec 4, 2007 (gmt 0)

10+ Year Member



Hello everyone, I have a question. It's been a while since I've done PHP programming and I must say that I have forgotten quite a few things.

I have a website that stores SESSION variables, which are set by the options that the user chooses. Once the user has finished and wants to e-mail his request to the admin he is taken to a process.php page. On that page I display all the options that the user has made and a FORM that prepares all my SESSION variables in hidden fields to be posted to the next page. An example is:

echo '<input type="hidden" name="email" value="'.$_SESSION['email'].'" />';

The user is prompted to press the SUBMIT button of that form to complete his request. The form action looks like this:

echo '<form action="success.php" method="post">';

As an added security feature I want to save all this information to a Database as it is being forwarded to my success.php page.

1) How do I go about doing this?

2) Is there any way of doing this without using onClick, and onSubmit?

3) Maybe instead of using a FORM to do all this work, what other options might there be?

For the record I know how to send MySql queries to my databases, but I'm simply baffled on how I can post the information to the next page and upload the data to my database at the same time on the same page.

Restrictions:
1) I don't want to use any Javascript, unless it can't be done any other way.
2) I need to send the data through the submit button, and not on the next page, nor by refreshing the same page and then moving to the next page.

PHP_Chimp

11:11 am on Dec 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could always use your success.php page to do both the email and the database addition for you. Then once those are complete forward the person on to another page.

All of the form variables will be in the $_POST array so you can use those for both the body of your email and to add to your database. Then assuming there are no problems with the mail use the header('Location: ..'); to move people on.

Check out the mail [uk3.php.net] functions and header [uk3.php.net]. Dont know if you are using MySQL [uk3.php.net], but almost every one is so check out that part of the manual for adding info to your database.
Using this format you can direct people to both a completed and did_not_complete page.

ted77

12:54 pm on Dec 4, 2007 (gmt 0)

10+ Year Member



Yes that is an option.

Lets say for arguments sake that success.php is a page that I cannot edit. I can put an in-between page that can be responsible for uploading the database information and then immediately redirecting to success.php with the variables, but supposing I don't want to do that.

So the sending of the information to the database and to the success.php page I want done on the page that the form is on, when the user presses the submit button and not earlier.

Also, "Yes", I am using MySql for my database.