Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

accessing dynamic var

Posted on 2004-04-07
5
Medium Priority
?
193 Views
Last Modified: 2006-11-17
in a form i use this code

// $numbOpt is set else where for this lets say $numbOpt = 5
$num=0;
while($num < $numbOpt) {
$num++;
print'
input name="opt$num" type="text">';
}      

in the next page is use this code which doesn't work

while($numbOpt > 0){
$Opt = "$opt".$numbOpt;
$query = "insert into PollOptions"
." ( `id` , `Qnumb` , `option` ) values "
."('','$Qid','$Opt')";
mysql_query($query);              
$numbOpt--;
}  

does anyone know how to do this, i can't figure it out. thanks

0
Comment
Question by:ocsurf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10779733
Try this:


while($numbOpt > 0){
$Opt = "$opt".$numbOpt;
$query = "insert into PollOptions('id','Qnumb','option') values ('','$Qid','$Opt')";
mysql_query($query);            
$numbOpt--;
}  
0
 
LVL 1

Accepted Solution

by:
ocsurf earned 0 total points
ID: 10779800
you just reposted my code that was cleaned up.

I figured it out  myself

I will post the code for everyone else:

            foreach($_POST as $key => $value)
            {
               if (strpos($key, "opt") === false) {
               }else{
                  $query = "insert into PollOptions"
                  ." ( `id` , `Qnumb` , `option` ) values "
                  ."('','$Qid','$value')";
                  mysql_query($query);                
               }
            }
0
 
LVL 19

Expert Comment

by:Michael701
ID: 10780400
i think you could have also used

$Opt = "$opt".$numbOpt;

echo $Opt.'='.$$Opt;
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question