Forum Moderators: coopster

Message Too Old, No Replies

help with empty()

empty not working when variable not empty

         

expert_21

6:46 pm on Jan 23, 2004 (gmt 0)

10+ Year Member



this is my php:

$pro1=addslashes($_POST['pro1']);
$pro2=addslashes($_POST['pro2']);
$pro3=addslashes($_POST['pro3']);
$pro4=addslashes($_POST['pro4']);
$pro5=addslashes($_POST['pro5']);

for ($i=1;$i==5;$i++){
if (!empty(${'pro'.$i}))
$pros.=${'pro'.$i}."\n";
}
echo nl2br($pros);

$pros return nothing, although $pro1 and $pro2 contain certain value. Any idea?

RussellC

6:55 pm on Jan 23, 2004 (gmt 0)

10+ Year Member



Maybe try isset() instead?

ergophobe

6:56 pm on Jan 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



your loop isn't doing anything - it will never execute because it is false the first time through and quits.


for ($i=1;$i==5;$i++){

seomike2003

11:07 pm on Jan 23, 2004 (gmt 0)



try this

$pro1=addslashes($_POST['pro1']);
$pro2=addslashes($_POST['pro2']);
$pro3=addslashes($_POST['pro3']);
$pro4=addslashes($_POST['pro4']);
$pro5=addslashes($_POST['pro5']);

for ($i=1;$i<=5;$i++){
if (!empty(${'pro'.$i}))
$pros.=${'pro'.$i}."\n";
}
echo nl2br($pros);

seomike2003

6:14 pm on Jan 25, 2004 (gmt 0)



expert_21

Hey dude I'd like to thank you for this post. I have a dynamic form that's fields are generated like this
req_1
req_2
so on...

I've been pulling out my hair trying to get my loop:

for($l=1;$l<=$amount;$l++){
if($l==$amount){
$sql_text2.="'$req_$l'";
} else {
$sql_text2.="'$req_$l', ";
}
}

to post the guts of my sql statement then insert the info in the fields to the database. I just happened to check this post and I saw how you grabed the variables and then tied them into a new variable so now I've changed my loop to this:
for($l=1;$l<=$amount;$l++){
if($l==$amount){
$sql_text2.="'${'req_'.$l}'";
} else {
$sql_text2.="'${'req_'.$l}', ";
}
}

It worked like a charm!
Thanks dude!

Mike