Solved

How to obtain the option choosed at the combobox?

Posted on 2013-06-04
9
333 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
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…

707 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