?
Solved

How to obtain the option choosed at the combobox?

Posted on 2013-06-04
9
Medium Priority
?
335 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 111

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 111

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 600 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 1400 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 111

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 111

Expert Comment

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

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. 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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
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.
Suggested Courses

752 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