/    Sign up×
Community /Pin to ProfileBookmark

how to submit data in a loop

I am trying to do the following:

A user will enter the name and address of a person on a form, and click submit to save it in a MySQL DB. I now want to allow the same user to enter the “name and address” of several persons using the same form. What I would like to do:

user opens form
user enters name and address of a person
user clicks either “submit and next” to continue to next person, or “submit and end” if there is no more “name and address” to enter.

Anyone knows of an online tutorial where I can learn to do this type of thing?

Thanks!

DL

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@so_is_thisNov 07.2006 — It is rather simple. Submitting the page to itself and using two submit buttons:
[code=html]
<input type="submit" name="MySubmit" value="Submit and Next">
<input type="submit" name="MySubmit" value="Submit and End">[/code]

Then your PHP code can perform its processing and test that value to determine what to do next:
[code=php]<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'):
# ...process data...
if($errors == 0
&& $_POST['MySubmit'] == 'Submit and End'):
# ...redirect...
exit;
endif;
endif;
# continue on and present HTML form
?>[/code]
Copy linkTweet thisAlerts:
@datalineauthorNov 15.2006 — Thanks so_is_this for the posting!

I've been trying to understand your code; I actually even tried it, but .....

In your code, "# ...process data..." is where I open the MySQL table and insert a record with the data. "# ...redirect..." is where I close all forms and go back to the home page. I fail to see the loop to present the form again and ask the user to enter the next "name and address".

I'm learning; so, please bear with me with these basic questions!

Thanks in advance!

DL
Copy linkTweet thisAlerts:
@theRamonesNov 15.2006 — your step :

1. user opens form (form1.php)

2. user enters name and address of a person (form1.php)

3. user clicks either "submit and next" to continue to next person, or "submit and end" if there is no more "name and address" to enter (form1)

on step 2, continue your proccess like this, if you still want to use 2 submit type:

3. on step 2, assume the form action go to response.php

4. on response.php, proccess all query. BUT, WITHOUT HTML CODE, just php code

5. on the last line, append with :
[code=php]
if($_POST['MySubmit'] == 'Submit and Next')) {
// still want input data
// redirect to form1.php
header("Location : form1.php");
exit(0);
/**
or you can add your confirmation, like this header("Location : form1.php?username=$username");
so in form1.php you can print out : user name for name = $username, had added
*/
}
elseif($_POST['MySubmit'] == 'Submit and End')) {
//this means user doesn't have more "name and address" to enter (form1)
// asume redirect to thank you page, thanks.php
header("Location : thanks.php");
exit(0);
}
[/code]

hope this help you to learn
Copy linkTweet thisAlerts:
@so_is_thisNov 16.2006 — I've been trying to understand your code; I actually even tried it, but .....

In your code, "# ...process data..." is where I open the MySQL table and insert a record with the data. "# ...redirect..." is where I close all forms and go back to the home page. I fail to see the loop to present the form again and ask the user to enter the next "name and address".[/QUOTE]

The loop is that if the user does *not* click the "Submit and End" button, then your logic falls through and displays the HTML form again.
Copy linkTweet thisAlerts:
@theRamonesNov 17.2006 — yes, you're right.

but although there isn't "Submit & Next" and "Submit & End" but only just "Submit", for do a loop it still must go back to the form page again.

previous logic is falls, but think about solution to use navigation to accomodate this logic falls
×

Success!

Help @dataline spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...