Solved

How to obtain the option choosed at the combobox?

Posted on 2013-06-04
9
331 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
  • 5
  • 2
  • 2
9 Comments
 
LVL 109

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 109

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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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 109

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 109

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 109

Expert Comment

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

829 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