473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Passing values from drop down menu

I've coded a script to populate a drop down menu from a database but I
can't seem to get the PHP script to pass the selected item. The
database only has two fields, ID and ITEM. I want the user to be able
to see all the choices and pick one. This choice would then be used
to update another database.

The drop down menu populates correctly. When I test for the variable
being passed, nothing is showing up. Here is the code:

<?php

include("connect.php");

if($_POST['testform']) {

print_r($HTTP_POST_VARS);
exit;
}

?>
<form name="testform" action="<?php echo $PHP_SELF; ?>" method="post">

<?php

$query = "SELECT * FROM mytable ORDER BY item";
$result = mysql_query($query) or die ("$text[cannotexecutequery]:
$query");

echo "<select name='id'>";
while($row=mysql_fetch_assoc($result))
{
echo "<option value=" . $row['id'].">".$row['item']."</option>";
}
echo "</select>";
echo "<input type='submit' value='Submit' name='testform'>
<input type='reset' value='Reset' name='reset'>
</form>";

?>
Feb 5 '06 #1
8 7435
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ba*******@yahoo.com wrote:
if($_POST['testform']) {

print_r($HTTP_POST_VARS);
exit;
}


And why exactly are you mixing $_POST and $HTTP_POST_VARS?

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

http://acm.asoc.fi.upm.es/~mr/
Proudly running Debian Linux with 2.6.12-1-686 kernel, KDE3.5.0, and PHP
5.1.2-1 generating this signature.
Uptime: 00:14:01 up 2 days, 3:42, 2 users, load average: 1.00, 0.78, 0.37

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFD5obe3jcQ2mg3Pc8RArdkAJ44JfVv2285R5z8VUEHpZ V8d3Kb1gCdGXwE
ZCfWyMkEPR4+72U6rVGEc8U=
=CUXn
-----END PGP SIGNATURE-----
Feb 6 '06 #2
On Mon, 06 Feb 2006 00:14:33 +0100, Iván Sánchez Ortega
<i.***************@rroba--mirame.punto.net> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ba*******@yahoo.com wrote:
if($_POST['testform']) {

print_r($HTTP_POST_VARS);
exit;
}


And why exactly are you mixing $_POST and $HTTP_POST_VARS?


Just hoping to see what variable values are being passed.

Feb 6 '06 #3
I tried a version of your script on my server and it worked fine - I
also tried changing the _POST to HTTP_POST_VARS (as Iván was
suggesting) which also worked - here is the sample:

<?php

if($HTTP_POST_VARS['testform']) {

print_r($HTTP_POST_VARS);
exit;
}

?>
<form name="testform" action="<?php echo $PHP_SELF; ?>" method="post">

<?php
print "<select name='id'>
<option value=\"1\" >1</option>
<option value=\"2\" >2</option>";
echo "</select>";
echo "<input type='submit' value='Submit' name='testform'>
<input type='reset' value='Reset' name='reset'>
</form>";

?>

Kitty
OpenSkyWebDesign.com

Feb 6 '06 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ba*******@yahoo.com wrote:
And why exactly are you mixing $_POST and $HTTP_POST_VARS?


Just hoping to see what variable values are being passed.


Then use something like:

<?php

if (isset($_POST))
{
echo '$_POST: '; print_r($_POST); exit;
}
else if (isset($HTTP_POST_VARS))
{
echo '$HTTP_POST_VARS: '; print_r($HTTP_POST_VARS); exit;
}

?>

Think about:
- - What if $_POST gets a value but $HTTP_POST_VARS does not? (and the other
way round)
- - What if $_POST['testform'] gets a value of 0, oran empty string, that will
evaluate as false?
- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

La política es un acto de equilibrio entre la gente que quiere entrar y
aquellos que no quieren salir.
-- Jacques Benigne Bossuet. (1627-1704) Filósofo francés.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFD5xJY3jcQ2mg3Pc8RAhyUAJsHjEPEvdb1bgo4etjZRJ IgHv8xVgCghsJy
bhKhGQRRTJ659hQWjH2+5fk=
=PHG+
-----END PGP SIGNATURE-----
Feb 6 '06 #5
I think I need to clarify what my objective is. Despite the code that
I posted which my attempt to test what is actually getting passed to
the program from the drop down menu selection, what I REALLY want is
to know HOW to pass the variable the correct way and then how to use
it in a MySQL INSERT statement. I tried the code you provided and
this is what is shown: $_POST: Array ( )

I know an array is what I'm up against, what I don't know is how to
deal with it. Does this help clear up what I am looking for?

On Mon, 06 Feb 2006 10:09:43 +0100, Iván Sánchez Ortega
<i.***************@rroba--mirame.punto.net> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ba*******@yahoo.com wrote:
And why exactly are you mixing $_POST and $HTTP_POST_VARS?


Just hoping to see what variable values are being passed.


Then use something like:

<?php

if (isset($_POST))
{
echo '$_POST: '; print_r($_POST); exit;
}
else if (isset($HTTP_POST_VARS))
{
echo '$HTTP_POST_VARS: '; print_r($HTTP_POST_VARS); exit;
}

?>

Think about:
- - What if $_POST gets a value but $HTTP_POST_VARS does not? (and the other
way round)
- - What if $_POST['testform'] gets a value of 0, oran empty string, that will
evaluate as false?


Feb 6 '06 #6
ba*******@yahoo.com wrote:
I think I need to clarify what my objective is. Despite the code that
I posted which my attempt to test what is actually getting passed to
the program from the drop down menu selection, what I REALLY want is
to know HOW to pass the variable the correct way and then how to use
it in a MySQL INSERT statement. I tried the code you provided and
this is what is shown: $_POST: Array ( )

I know an array is what I'm up against, what I don't know is how to
deal with it. Does this help clear up what I am looking for?


Looks like you did:

echo '$_POST: '; print($_POST); exit;

Instead of

echo '$_POST: '; print_r($_POST); exit;
^^

For an array, print() will print "Array()";

print_r() will print the contents of an array.

You should find the value from the previous form in $_POST['id'].

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 6 '06 #7

<ba*******@yahoo.com> wrote in message
news:im********************************@4ax.com...
I think I need to clarify what my objective is. Despite the code that
I posted which my attempt to test what is actually getting passed to
the program from the drop down menu selection, what I REALLY want is
to know HOW to pass the variable the correct way and then how to use
it in a MySQL INSERT statement. I tried the code you provided and
this is what is shown: $_POST: Array ( )
once you've validated $_POST['id'],
mysql_query("INSERT INTO sometable(somecolumn,anothercolumn)
VALUES ('somestring','" .
str_replace(";","",mysqlreal_escape_string($_POST['id'])) . "')");

the functions should prevent SQL INJECTION. you can eliminate somecolumn
and somestring - i just put it in for completentess of example. your string
data should be enclosed in quotes. if it is numeric data, then don't
surround it with quotes.

I know an array is what I'm up against, what I don't know is how to
deal with it. Does this help clear up what I am looking for?

On Mon, 06 Feb 2006 10:09:43 +0100, Iván Sánchez Ortega
<i.***************@rroba--mirame.punto.net> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ba*******@yahoo.com wrote:
And why exactly are you mixing $_POST and $HTTP_POST_VARS?

Just hoping to see what variable values are being passed.


Then use something like:

<?php

if (isset($_POST))
{
echo '$_POST: '; print_r($_POST); exit;
}
else if (isset($HTTP_POST_VARS))
{
echo '$HTTP_POST_VARS: '; print_r($HTTP_POST_VARS); exit;
}

?>

Think about:
- - What if $_POST gets a value but $HTTP_POST_VARS does not? (and the
other
way round)
- - What if $_POST['testform'] gets a value of 0, oran empty string, that
will
evaluate as false?

Feb 17 '06 #8

<ba*******@yahoo.com> wrote in message
news:im********************************@4ax.com...
I think I need to clarify what my objective is. Despite the code that
I posted which my attempt to test what is actually getting passed to
the program from the drop down menu selection, what I REALLY want is
to know HOW to pass the variable the correct way and then how to use
it in a MySQL INSERT statement. I tried the code you provided and
this is what is shown: $_POST: Array ( )

I know an array is what I'm up against, what I don't know is how to
deal with it. Does this help clear up what I am looking for?

On Mon, 06 Feb 2006 10:09:43 +0100, Iván Sánchez Ortega
<i.***************@rroba--mirame.punto.net> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ba*******@yahoo.com wrote:
And why exactly are you mixing $_POST and $HTTP_POST_VARS?

Just hoping to see what variable values are being passed.

maybe I can save you some time. If you used name="id", $_POST['id'] will
contain your selected value or nothing at all. you can try using isempty()
on it and see if that works.

if your select element were a multiple-select, then you should specify
select's name as id[] which signals to PHP to return an array of values.
then you would
foreach ($_POST['id'] as $val) {
do something with $val
}


Then use something like:

<?php

if (isset($_POST))
{
echo '$_POST: '; print_r($_POST); exit;
}
else if (isset($HTTP_POST_VARS))
{
echo '$HTTP_POST_VARS: '; print_r($HTTP_POST_VARS); exit;
}

?>

Think about:
- - What if $_POST gets a value but $HTTP_POST_VARS does not? (and the
other
way round)
- - What if $_POST['testform'] gets a value of 0, oran empty string, that
will
evaluate as false?

Feb 17 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Xerxes | last post by:
Hi, how can I pass the returned value from Javascript to PHP? I have: ------------------------------------------------------------------------ ------ if ( x>y) {
4
by: timwap | last post by:
I hava a Java Applet that produces a DTMF tone at a certain time of day. There are 4 parameters to the Applet, they are hour = Hour of triggered event 00~23 min = minute of triggered event 00~59...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
1
by: VbUser25 | last post by:
hi.. i have a drop-down menu with a list of products.when i select any one product i open a popup displaying hte product categories in it.i then enter the no. of items i want.and finally when i...
0
by: kajir | last post by:
Hi, I am new at using ASP.Net 2.0. I have various drop down lists on my master page. They refer to an SQL database. I also have a menu on the master page. I can select the values in the drop...
2
by: mrjoka | last post by:
hi guys, i'm building a web site where i have a lot of pages, in the default page i'm having a menu in this menu i have a callendar a drop down list, in the callendar i need to remember the date...
4
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me...
0
sharyn
by: sharyn | last post by:
is there any way short of calling a page with get/posts to pass values (like an array) back to a python program? I create a dropdown menu in python (created by calling a python service) and upon...
11
SHOverine
by: SHOverine | last post by:
I have an issue with a drop down menu that I am hoping you all can help me with. The issue is when I press "Submit", my code prints back values from a form I developed (eventually I will write them...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.