Forum Moderators: coopster

Message Too Old, No Replies

Passing form values

can't get pulldown to pass variable value

         

overlac

10:53 am on Oct 11, 2005 (gmt 0)

10+ Year Member



I have a form with two drop down boxes that are hard coded as in the example below, and another drop down (pull down) box that is populated as a result of a MySQL query. All appears to work as it should with
the exception that after choices have been made and the submit button clicked, (to either enter the data into another database OR work together in another query - I've tried both), the field that was
populated by the initial query does not pass it's data as the hard coded fields do. In other words, the 'target_month' below passes user data to $target_month in mmonth.php but the data in the queried cell 'contractor' does not pass to $contractor in mmonth.php - can anyone tell me why is that? TIA - appreciate all replies... form code follows:

<html>
<head>
<title>Committed Dollars</title>
</head>
<body>
<center><h2>Committed Dollars Database</h2></center><p>
<form method="post" action="committedmonth.php">
<input type="hidden" name="id" value="NULL">
<center>
<table border="8">
<tr>
<td><b>Project:</b></td><td align="left"><input type="text" name="project_description" size="45" maxlength="150" value=""></td>
</tr>
<tr>
<td><b>Estimated Cost:<font color=white>.........</font>$</b></td><td align="left"><input type="text" name="estimated_cost" size="8" maxlength="8" value=""><font color=red> Numeric value ONLY</font></td>
</tr>
<tr>
<td><b>Date:</b></td>
<td align="left"><input type="text" name="date" size="8"
maxlength="10" value="<? print strftime("%m/%d/%Y");?>"></td>
</tr>
<tr>
<td><b>Name:</b></td>
<td><select name="eename">
<option value = "Greg">Greg</option>
<option value = "Jeff">Jeff</option>
<option value = "Jim">Jim</option>
<option value = "Richard">Richard</option>
<option value = "Stephen">Stephen</option>
<option value = "Terry">Terry</option>
<option value = "Chris">Chris</option>
</select>
</td>
</tr>

<tr>
<td>Select Month</td><td>
<select name="target_month">
<?php
for ($select_month = 1; $select_month <= 12; $select_month++) {
$select = ( date('m') == $select_month )? 'selected="selected"' : '';
$foo = date( 'F', strtotime( date('Y') . "-{$select_month}-01" ) );
echo "\t<option $select value='$select_month'>$select_month ($foo)</option>\n";
}
?>
</select>
</tr>

<td>Select Year</td><td>
<select name="fiscal_year">
<?php
$t_date = date('Y');
for ($select_year = 2003; $select_year <= $t_date; $select_year++) {
$select = ( date('Y') == $select_year )? 'selected="selected"' : '';
echo "\t<option $select value='$select_year'>$select_year</option>\n";
}
?>
</select>
</tr>

<td>Select Contractor</td><td>
<select name="contractor">

<?php
$hostName = "localhost";
$userName = "overlac";
$password = "over321";
$dbName = "committed";
$table = "committed_tbl";
// make connection to database
mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");

mysql_select_db($dbName) or die("Unable to select database $dbName");

// Select all the fields in all the records of the Employees table

$query = "SELECT DISTINCT contractor
FROM $table";

$result = mysql_query($query);

// Determine the number of vendors

$number = mysql_numrows($result);

// Create drop-down menu of vendor names

print "View committedcjover Database List to assist in above search:
<form action=\"committedmonth.php\" method=\"post\">
<select name=\"committedcjover\">
<option value=\"\">Select a Vendor</option>";
for ($i=0; $i<$number; $i++) {
$contractor = mysql_result($result,$i,"contractor");
print "<option value=\"$committedcjover\">$contractor</option>";

}
mysql_close();
?>
</tr>
</select>

<tr>
<td colspan="2" align="center"><input type="submit" value="Enter"></td>
</tr>
</table>
</form>
</center><p>
</body>
</html>

Iguana

12:08 pm on Oct 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could it be that you have a </tr> before the end of your contractor </select>?

overlac

1:50 pm on Oct 11, 2005 (gmt 0)

10+ Year Member



Assuming you're referring to the one 11 lines up from bottom, I just tried removing that and it had no effect. Thanks very much for the reply though... Appreciate it.

jatar_k

2:57 pm on Oct 11, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld overlac,

the second form tag is the likely culprit

<form action=\"committedmonth.php\" method=\"post\">

overlac

4:31 am on Oct 12, 2005 (gmt 0)

10+ Year Member



I tried doing the slashes to 'rem' out that statement. As I experimented with the slashes, in most cases the form would not load and just came to a white blank screen (fatal error equivalent :) - I tried working from there to find the issue and still no luck in passing the value of that variable. Thanks for your reply...

overlac

4:33 am on Oct 12, 2005 (gmt 0)

10+ Year Member



I guess one question I have... Is there an easier way to query a database and fill the drop down menu with values of a particular column within a table?

dmmh

6:05 am on Oct 12, 2005 (gmt 0)

10+ Year Member



you really need to start reading jatar_k's reply.....

overlac

11:53 am on Oct 12, 2005 (gmt 0)

10+ Year Member



Thanks jatar_k,

Any ideas on how to handle the 2nd tag (<form action=\"committedmonth.php\" method=\"post\">)? when I commented out those lines with slashes and the form stopped loading.

dcrombie

12:03 pm on Oct 12, 2005 (gmt 0)



What you probably need to do is take the _HTML_ output of your script (the PHP code is not relevant in this issue) and run it through the W3C Validator to see where the HTML might be broken.

overlac

12:03 pm on Oct 12, 2005 (gmt 0)

10+ Year Member



second form tag looks as follows and works with slashes where they are but still, will not pass the value of 'contractor'. HELP! :-)

// Create drop-down menu of vendor names

//print "View committedcjover Database List to assist in above search:
// <form action=\"committedmonth.php\" method=\"post\">
// <select name=\"committedcjover\">
// <option value=\"\">Select a Vendor</option>";
for ($i=0; $i<$number; $i++) {
$contractor = mysql_result($result,$i,"contractor");
print "<option value=\"$committedcjover\">$contractor</option>";

}

Iguana

12:30 pm on Oct 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<option value=\"$committedcjover\">$contractor</option>

Where is the variable that you are passing as the value of the option element coming from? I can't see it from your code

overlac

1:32 pm on Oct 13, 2005 (gmt 0)

10+ Year Member



Good catch Iguana - thank you SO much - WOW, you found the bug... As I recall, I placed the committedcjover in there as the table to pull the contractor variable data from to populate the pulldown. Through my own novice debugging, I apparently somehow got the $ in there ahead of it and guess what, I just removed the $ in front of committedcjover and it WORKS FINE... Thanks so much... This one had really been driving me 'krazy'. lol

Thanks to EVERYONE for your replies. I just stumbled across this forum recently and can see how dedicated most of you are and the sense of community that exists here...

>> Iguana wrote: <option value=\"$committedcjover\">$contractor</option>
Where is the variable that you are passing as the value of the option element coming from? I can't see it from your code

overlac

1:39 pm on Oct 13, 2005 (gmt 0)

10+ Year Member



To keep the confusion factor down and the record straight... ;-) After I got done yelling whoo hooo throughout my house at 6:30am, noticed that I had SOMETHING there that I was expecting but not quite right yet. I moved it to read "<option value=\"$contractor\" >$contractor</option> and it works fine. thanks again... :-)

<option value=\"$committedcjover\">$contractor</option>
Where is the variable that you are passing as the value of the option element coming from? I can't see it from your code

Iguana

4:15 pm on Oct 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad to be of help Overlac

enjoy your time at Webmaster World