I have a drop down menu that I want to write the value of its selected item to a database.
the code in action
The menu is up and running and works great.
The database is running and is creating a new row each time the submit button is pressed in the form (but the cells are empty)
I have the php page display the values of the two variable once you click the submit button, but they too are empty...that's how I know I'm not capturing the data to write it.
Also, if you look in the URL, once you click the SUBMIT...you will see indeed that the form is working properly...in terms of getting the selected values.
PROBLEM : How can I assign a variable to capture the value from the drop down menu to INSERT into the mySQL database?
The following is the code that works...with the exception of the
$job_start_date and $job_close_date ; these are the two variables I want to write to.
<?php
/**
* This file creates a simple date picking drop down box prefilled with the
* next 60 days dates and days of the week.
*
* This function is provided 'AS IS' and is therefore not liable for any damage
* caused to a system using it.
*
* This code may be used by anyone aslong as the header is kept and recognition
* given.
*
*
* @author Kenneth Brill
* @version 1.0
* #email [email]kbrill@multi.com[/email]
*/
function datemaker($size=365) {
// $size = the number of days to display in the drop down
// $default = Todays date in m:d:Y format (SEE DATE COMMAND ON [url]WWW.PHP.NET[/url])
// $skip = if set then the program will skip Sundays and Saturdays
// $fieldname gets carried over into the function
$fieldname = $GLOBALS["fieldname"];
$skip=0;
echo "<select name=$fieldname STYLE=\"font:11px tahoma, geneva, arial, sans-serif;\">\n";
for ($i = 0; $i <= $size; $i++) {
$theday = mktime (0,0,0,date("m") ,date("d")+$i ,date("Y"));
$option=date("l, M j, Y",$theday);
$value=date("Y-m-d",$theday);
$dow=date("D",$theday);
if ($value == $default) {
$selected="SELECTED";
} else {
$selected="";
}
if (($dow!="Sun" and $dow!="Sat") or !$skip) {
echo "<option value=\"$value\" $selected>$option</option>\n";
}
}
echo "</select>\n";
}
// END OF THE FUNCTION
// LOGIN
// This is the login info: 'host', 'username', 'password'
$conn = mysql_connect("localhost", "joe", "millionaire");
// specify database to be accessed
mysql_select_db("whiterabbit",$conn);
// If the submit button is pressed, it will process the form
if ($submit) {
$sql = "INSERT INTO timegrab(job_start_date, job_close_date) VALUES ('$job_start_date','$job_close_date')";
$result = mysql_query($sql);
// Display thank you message
echo "<span class=\"bolder\">job start date : $job_start_date <br> job close date : $job_close_date</span><br>";
echo "<a href=\"#\" target=\"_self\">no location selected yet</a><br><br>";
} else {
// If the submit button hasn't been pressed, it will display the entry form
echo "<form name=form1>";
echo ("Start Date ");
// define the value of the selection drop down menu name to pass to the function
$fieldname = startdate;
// define the value of the selection drop down menu name to pass the value to the dbase
$job_start_datemaker = datemaker($size=365);
$job_start_date = form1.startdate.selected;
echo "<br /><br />";
// second drop down
echo ("Close Date ");
$fieldname = closedate;
$job_close_datemaker = datemaker($size=14);
$job_close_date = form1.closedate.selected;
echo "<input type=submit name=submit value=Send Dates To Next Page></form>";
}
?>