Jump to content

Recommended Posts

I work mostly with flash but use php to talk to databases so I am not strong in php. I am passing some variables from flash that I want to add to a database. They are in the form of sid0=A&sid1=B&sid2=C and so on, n is the total number of variables passed. I believe the server I am working on uses PHP 4.1.

 

My code is:

 

if($n>="1"){
for($i=0; $i<$n;$i++){
$sql= "INSERT INTO comserlinks SET comid ='$cid', serid='$sid[$i]'";
$result=mysql_query($sql1);
}
if($result){
echo "Cresult=OK";}
else{
echo "Cresult=No";
}}else{
echo "Cresult=Problem: ".mysql_error();
}

 

if I echo $sid0.$sid1.$sid2 etc I can see that every thing is passed OK but if I echo $sid[$i] I get nothing....can any one point out what I'm doing wrong?

 

TW

 

Link to comment
https://forums.phpfreaks.com/topic/68639-solved-for-loop-help/
Share on other sites

If im getting this right u have variables sid1, sid2, sid3, ..... , sidn. Trying to echo $sid[$i] will print u nothing if $sid isnt an array and in this case i can see it isnt. U can try smth like this:

 

for($i=1; $i<=$n; $i++){
     echo ${sid . $i};
}

 

In this way u concatenate "sid" with $i to call a variable.

Link to comment
https://forums.phpfreaks.com/topic/68639-solved-for-loop-help/#findComment-345047
Share on other sites

Perfect works:

basically i'm passing the values from Flash in the url: www.domain.com/page.php?n=2&cid=232&sid0=1&sid1=55&

 

I needed to add them to a database and I'm now doing so like this:

 

for($i=0; $i<$n;$i++){
$sql1= "INSERT INTO comserlinks SET comid ='$cid', serid='${sid . $i}'";
$result1=mysql_query($sql1);}

 

Thanks for the help...

Link to comment
https://forums.phpfreaks.com/topic/68639-solved-for-loop-help/#findComment-345288
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.