/    Sign up×
Community /Pin to ProfileBookmark

Form data posting problem

Hi all,

I want to concatenate 2 things that is first name and last name.but in foreach statement i am getting error.Hope fully foreach statement doesnot take 2 posts at a time.

What i want to do is:

First name 1=A
Last name 1=B
First name 2=C
Last name 2=D

So i want the out put will be AB and CD. But when i am doing it in other way then i am getting AC and BD which is incorrect.

//if the form is being submitted
if(isset($_POST[“submit1”]))
{

unset($fname);
foreach($_POST[‘fname’],$_POST[‘fname’], as $key=> $value)
{
$fname .= $value;
$lname .= $value;
$name .= $fname.$lname.”,”;
}
}//Post finish

<form action=”detail.php” method=”post” name=”frm” style=”margin:0px”>
for($i=1;$i<=2;$i++)
{
?>
<tr>
<td width=”28%” height=”30″>First Name
<?=$i;?>
<font color=#ff0000>*</font>:</td>
<td width=”72%” height=”30″>
<input maxlength=60 name=”fname[]” size=25>
</td>
</tr>

<tr>
<td width=”28%” height=”30″>Last Name
<?=$i;?>
<font color=#ff0000>*</font>:</td>
<td width=”72%” height=”30″>
<input maxlength=60 name=”lname[]” size=25>
</td>
</tr>
<? } ?>

<input name=”submit1″ type=”submit” value=”Proceed” class=”button”>

Please suggest me what should i do to get the desired output.i think i am doing mistakes at some other places.

Thanks for your help in advance.
Raj

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@chazzyMay 19.2006 — what error you have?
Copy linkTweet thisAlerts:
@raj_2006authorMay 19.2006 — I am getting this error:

Parse error: parse error, unexpected ',' in C:xampphtdocscoursenewcoursedetail.php on line 51// that is in foreach statement
Copy linkTweet thisAlerts:
@GarySMay 19.2006 — The loop you have to process the $_POST looks strange - there should only be two parts,,, which is why it is falling over on the second comma (there should be only one).

As you've used a counter to generate the fields, why not use a counter to process them:

[code=php]if(isset($_POST["submit1"]))
{
for($i=0;$i<2;$i++){

echo $_POST['fname'][$i] . ' ' . $_POST['lname'][$i] ;

}

}//Post finish[/code]


That should, I hope, give the intended result.
Copy linkTweet thisAlerts:
@raj_2006authorMay 19.2006 — Excellent......its working.....Great....?

i just need to change the for loop and the post statement a bit and its done......

Thanks a lot again for your earnest help.....Raj
×

Success!

Help @raj_2006 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 5.7,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...