Solved

How to obtain the option choosed at the combobox?

Posted on 2013-06-04
9
332 Views
Last Modified: 2013-06-04
Hi Experts!

How to obtain the option choosed at the combobox, accordingly with the code bellow?
(what variable stores it?)
Something more is necessary to do  to obtain it?

<?php
     $sql = "select sb_cccx, cx_info, substr(descricao,1,25) as descricao from cccx where ativa=1 order by sb_cccx";
     $query = mysql_query($sql);
     while ( $results[] = mysql_fetch_object ( $query ) );
     array_pop ( $results );
?>


<select name="the_name">
     <?php foreach ( $results as $option ) : ?>
          <option value="<?php echo $option->sb_cccx; ?>"><?php echo $option->descricao; ?></option>
     <?php endforeach; ?>
</select>

Open in new window


Thanks in advance!
0
Comment
Question by:Eduardo Fuerte
[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
  • 2
  • 2
9 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39218860
Please use var_dump($_REQUEST) in the action= script.  Please post the output here.  You will probably find the data in $_GET['the_name'] or $_POST['the_name'].
0
 
LVL 7

Expert Comment

by:Robert Saylor
ID: 39218865
In your form tag when you post your form.

IE:

<form action="somefile.php" method="POST">

When you post to that file the var will be $_POST['the_name']

Also, if you use a method of GET the var would then be $_GET['the_name']
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39218882
Here's the code with comments added.  Not sure it's doing what you want (a little confused about why the query selects a column that is not used, and why array_pop() is in the code).

<?php
     // CONSTRUCT A QUERY STRING
     $sql = "select sb_cccx, cx_info, substr(descricao,1,25) as descricao from cccx where ativa=1 order by sb_cccx";
     
     // EXECUTE THE QUERY AND PUT THE RESULTS RESOURCE INTO $query
     $query = mysql_query($sql);
     
     // ITERATE OVER THE RESULTS SET ADDING EACH ROW TO THE $results ARRAY
     while ( $results[] = mysql_fetch_object ( $query ) );
     
     // DISCARD THE LAST ROW FROM THE $results ARRAY
     array_pop ( $results );
?>


<select name="the_name">
     <?php 
     
     // ITERATE OVER THE RESULTS 
     foreach ( $results as $option ) : ?>
          <option value="<?php echo $option->sb_cccx; ?>"><?php echo $option->descricao; ?></option>
     <?php 
     // END OF THE ITERATOR
     endforeach; ?>
</select>

Open in new window

And going forward you will need to get off the MySQL extension.  It is being removed from PHP.  This article explains why and shows what you must do to keep your scripts running.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Eduardo Fuerte
ID: 39219030
I've tryed your suggestion but I must have made a mistake...

Alternativelly I've used

In the caller program

<?php
session_start()
....
 $_SESSION["the_name"] = $selectValue;
...
?>

Open in new window

and then at the called program:

<?php
session_start()
...
 $nome   = $_SESSION['the_name'];
...
?>

Open in new window

My doubt is how and why to use

caller, does the variable must go here? how?:

<?php
...
$_GET['the_name']
...
<form action="somefile.php" method="POST" "does the variable must go here? how?>
?>

Open in new window


called:

<?php
...
$_POST['the_name']
...
<form action="somefile.php" method="POST">
?>

Open in new window


Could you explain, please?
0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 150 total points
ID: 39219112
Please read this tutorial over carefully.  It shows how HTML forms interact with PHP scripts.
http://php.net/manual/en/tutorial.forms.php
0
 
LVL 7

Accepted Solution

by:
Robert Saylor earned 350 total points
ID: 39219185
Ok, here is a basic form post:

page1.php

<form method="post" action="page2.php">
<select name="help">
   <option value="1">Test 1</option>
   <option value="2">Test 2</option>
</select>
<input type="submit" value"Submit The Form">
</form>

Open in new window


page2.php

<?php
print "You have selected option " . $_POST['help'] . ". Thank you for using our form.";
?>

Open in new window


Whatever you put in the HTML option value will be the value of $_POST[help] when they select it in the dropdown and click on the submit button.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39219222
Hmm... Maybe this would help.
http://www.sitepoint.com/books/phpmysql5/
0
 

Author Comment

by:Eduardo Fuerte
ID: 39220387
Thank you for the assistance!
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39220490
Thanks for the points (and invest in that book!), ~Ray
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

733 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