/    Sign up×
Community /Pin to ProfileBookmark

for loop help – please !!

Hello,

I have a form ( named c_sal_ord_fm.php ) with multiple line input generated like this:

for($i=0;$i<15;$i++){

echo “
<tr>
<td><input type=’TEXT’ name=’so_dat$i’ value = ‘$so_dat’
size = ’10’ maxlength=’10’/></td>

<td><input type=’TEXT’ name=’so_num$i’ value = ‘$so_num’
size = ‘6’ maxlength=’10’/></td>
} // end of loop

I want to validate the input in the calling script ( named c_sal_ord.php )
with this:

for($i = 0; $i < 15; $i++){

$so_dat = strip_tags(trim($_POST[“so_dat$i”])); // should be $so_dat$i ???
$so_num = strip_tags(trim($_
POST[“so_num$i”]));
$acc_nam = strip_tags(trim($_POST[“acc_nam$i”]));
$prod = strip_tags(trim($_
POST[“prod$i”]));
$price = strip_tags(trim($_POST[“price$i”]));
$qty = strip_tags(trim($_
POST[“qty$i”]));

/*
*
Check the date field
*/

if(!ereg(“^[0-9]{2}[0-9]{2}[0-9]{4}$”,$so_dat)){ // should be $so_dat$i
$mess = “yes”;
$message1 = “All dates must be formated dd-mm-yyyy”;
$message2 = ” “;
require_once (“c_sal_ord_fm.php”);
exit();
} // endif

[ plus others – then update the database if everything is ok ]

} // end of loop

As you can see the validation calls the form again. The problem is that I was
trying not to loose the data that was keyed in by setting the value
in the form as ‘$so_dat’ and updating it from the form when submitted.

Trouble is this only works for one line. I really need to change the variable
name with the $i each time. Of course $so_dat$i doesn’t work. I guess
two $ signs is not allowed in one variable.

Does anyone know how I do this ?

Thanks
David.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 24.2005 — [EDIT: never mind, I misunderstood the original question.]
Copy linkTweet thisAlerts:
@grailquester5Apr 24.2005 — Have you tried concatenating the variables?

$so_dat.$i

Just a first take on glancing at the question/code. I'll have to pick thru more in-depth to really get a handle on it...
×

Success!

Help @DaveinLondon 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.25,
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,
)...