Solved

How to obtain the option choosed at the combobox?

Posted on 2013-06-04
9
328 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 108

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 6

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 108

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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 108

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 6

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 108

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 108

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now