Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Dropdown Help needed

Status
Not open for further replies.

about2flip

Technical User
Nov 21, 2003
31
US
Hello:

I have a form that I am trying to make a dropdown menu using a phpscript. I keep getting a tstring error on line 21 which is function make_calendar_pulldowns...

I am using php4, is this the correct format for php 4? If someone could cut and past the script into their editor and see what is wrong I highly appreciate it. Also I need to know what variables I uses to write into my sql db. Thanks.

<?
$page_title ="EXDQ TRUCKING ADMIN";
include ('includes/header.html');
?>
<h1 id="mainhead">Expedited Trucking Admin</h1>
<p>
<?
echo 'Today is ' .date('l') . ' . The current Time is ' . date ('g:i a') .'.';
?>
</p>
<Form method ="post" action="addload.php">
<table width="557" border="0">
<tr>
<td width="116">Shipper Origin:</td>
<td width="431"><input name="shipperorg" type="text" size="20" maxlength="10" /></td>
</tr>
<tr>
<td><label>Pick Up Date:</label></td>
<td>
<?
fuction make_calender_pulldowns($m=NULL, $d=NULL, $y=NULL) {

// Make the months array.
$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December');

// Make the months pull-down menu.
echo '<select name="month">';
foreach ($month as $key => $value) {
echo "<option value=\"$key\"";
if ($key == $m) { //Preselect.
echo ' selected="selected"';
}
echo ">$value</option>\n";
}
echo '</select>';

// Make the days pull-down menu.
echo '<select name="day">';
for ($day = 1; $day <= 31; $day++) {
echo "<option value=\"$day\"";
if($day==$d) {//Preselect.
echo 'selected="selected"';
}
echo ">$day</option>/n";
}
echo '</select>';

// Make the years pull-down menu.
echo '<select name="year">';
for($year = 2006; $year <=2015; $year++) {
echo "<option value=\"$year\"";
if ($year == $y) {//Preselect.
echo 'selected="selected"';
}
echo ">$year</option>\n";
}
echo '</select>';

// Get today's information and call the function.
$dates=getdate();
make_calendar_pulldowns
($dates['mon'], $dates['mday'], $dates['year']);
?>
</td>
</tr>
<tr>
<td>Origin City: </td>
<td><input name="origincity" type="text" id="origincity" size="35" maxlength="35" /></td>
</tr>
<tr>
<td>Origin State: </td>
<td><input name="originstate" type="text" id="originstate" size="5" maxlength="2" /></td>
</tr>
<tr>
<td>Destination City: </td>
<td><input name="destcity" type="text" id="destcity" size="35" maxlength="35" /></td>
</tr>
<tr>
<td>Destination State: </td>
<td><input name="deststate" type="text" id="deststate" size="5" maxlength="2" /></td>
</tr>
<tr>
<td>Loadtype:</td>
<td><select name="loadtype" id="loadtype">
<option>Please Select</option>
<option value="Outbound">Outbound</option>
<option value="Inbound">Inbound</option>
</select> </td>
</tr>
<tr>
<td>Euipment Type: </td>
<td><select name="equiptype" id="equiptype">
<option>Please Select</option>
<option>FBTL</option>
</select> </td>
</tr>
<tr>
<td>Weight:</td>
<td><input name="weight" type="text" id="weight" size="10" maxlength="10" /></td>
</tr>
<tr>
<td>Miles:</td>
<td><input name="miles" type="text" id="miles" size="10" maxlength="10" /></td>
</tr>
</table>
<p>
<input name="submit" type="submit" id="submit" value="Add New Load" />
</p>
<p>&nbsp; </p>

 
In line 21 you mistyped 'function':
Code:
fuction make_calender_pulldowns...
 
Thanks!! I fixed that but now I am getting an error on line 112, and nothing is there.

<?
$page_title ="EXDQ TRUCKING ADMIN";
include ('includes/header.html');
?>
<h1 id="mainhead">Expedited Trucking Admin</h1>
<p>
<?
echo 'Today is ' .date('l') . ' . The current Time is ' . date ('g:i a') .'.';
?>
</p>
<Form method ="post" action="addload.php">
<table width="557" border="0">
<tr>
<td width="116">Shipper Origin:</td>
<td width="431"><input name="shipperorg" type="text" size="20" maxlength="10" /></td>
</tr>
<tr>
<td><label>Pick Up Date:</label></td>
<td>
<?
function make_calendar_pulldowns($m=NULL, $d=NULL, $y=NULL) {

// Make the months array.
$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December');

// Make the months pull-down menu.
echo '<select name="month">';
foreach ($month as $key => $value) {
echo "<option value=\"$key\"";
if ($key == $m) { //Preselect.
echo ' selected="selected"';
}
echo ">$value</option>\n";
}
echo '</select>';

// Make the days pull-down menu.
echo '<select name="day">';
for ($day = 1; $day <= 31; $day++) {
echo "<option value=\"$day\"";
if($day==$d) {//Preselect.
echo 'selected="selected"';
}
echo ">$day</option>/n";
}
echo '</select>';

// Make the years pull-down menu.
echo '<select name="year">';
for($year = 2006; $year <=2015; $year++) {
echo "<option value=\"$year\"";
if ($year == $y) {//Preselect.
echo 'selected="selected"';
}
echo ">$year</option>\n";
}
echo '</select>';

// Get today's information and call the function.
$dates=getdate();
make_calendar_pulldowns
($dates['mon'], $dates['mday'], $dates['year']);
?>
</td>
</tr>
<tr>
<td>Origin City: </td>
<td><input name="origincity" type="text" id="origincity" size="35" maxlength="35" /></td>
</tr>
<tr>
<td>Origin State: </td>
<td><input name="originstate" type="text" id="originstate" size="5" maxlength="2" /></td>
</tr>
<tr>
<td>Destination City: </td>
<td><input name="destcity" type="text" id="destcity" size="35" maxlength="35" /></td>
</tr>
<tr>
<td>Destination State: </td>
<td><input name="deststate" type="text" id="deststate" size="5" maxlength="2" /></td>
</tr>
<tr>
<td>Loadtype:</td>
<td><select name="loadtype" id="loadtype">
<option>Please Select</option>
<option value="Outbound">Outbound</option>
<option value="Inbound">Inbound</option>
</select> </td>
</tr>
<tr>
<td>Euipment Type: </td>
<td><select name="equiptype" id="equiptype">
<option>Please Select</option>
<option>FBTL</option>
</select> </td>
</tr>
<tr>
<td>Weight:</td>
<td><input name="weight" type="text" id="weight" size="10" maxlength="10" /></td>
</tr>
<tr>
<td>Miles:</td>
<td><input name="miles" type="text" id="miles" size="10" maxlength="10" /></td>
</tr>
</table>
<p>
<input name="submit" type="submit" id="submit" value="Add New Load" />
</p>
<p>&nbsp; </p>

 
how would I enter the months, day and year into the DB? Do I have to have seperate columns for each?

This is my addload.php script:

<?
$page_title ="ADMIN";
include ('includes/header.html');
?>
<h1 id="mainhead">Expedited Trucking Admin</h1>
<?
echo 'Today is ' .date('l') . ' . The current Time is ' . date ('g:i a') .'.';<br>
?>
<?

if ((!$_POST[shipperorg]) || (!$_POST[origincity]) || (!$_POST[originstate])
|| (!$_POST[destcity]) || (!$_POST[deststate]) || (!$_POST[loadtype]) || (!$_POST[equiptype])) {
header( "Location: exit;
}
include("dbinfo.php");
$table_name = "loads";
// open connection
$connection = mysql_connect($host, $username, $password) or die ("Unable to connect!");

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

// create query
$query = "INSERT INTO $table_name (shipperorg, origincity, originstate, destcity, deststate, loadtype, equiptype, weight, miles) VALUES ('$_POST[shipperorg]', '$_POST[origincity]', '$_POST[originstate]', '$_POST[destcity]', '$_POST[deststate]', '$_POST[loadtype]', '$_POST[equiptype]', '$_POST[weight]', '$_POST[miles]')";

// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

// print message with ID of inserted record
echo "New record inserted with ID ".mysql_insert_id();

// close connection
mysql_close($connection);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<p>

<h1> Adding Information to <? echo "$table_name"; ?>
</h1>
</p>
<table width="316" border="0">
<tr>
<td width="161"><strong>Shipper Origin:</strong></td>
<td width="145"><? echo "$_POST[shipperorg]"; ?></td>
</tr>
<tr>
<td><strong>Pick Date: </strong></td>
<td><? echo "$_POST[pickdate]"; ?></td>
</tr>
<tr>
<td><strong>Origin City: </strong></td>
<td><? echo "$_POST[origincity]"; ?></td>
</tr>
<tr>
<td><strong>Origin State: </strong></td>
<td><? echo "$_POST[originstate]"; ?></td>
</tr>
<tr>
<td><strong>Destination City: </strong></td>
<td><? echo "$_POST[destcity]"; ?></td>
</tr>
<tr>
<td><strong>Destination State: </strong></td>
<td><? echo "$_POST[deststate]"; ?></td>
</tr>
<tr>
<td><strong>Load Type: </strong></td>
<td><? echo "$_POST[loadtype]"; ?></td>
</tr>
<tr>
<td><strong>Equipment Type: </strong></td>
<td><? echo "$_POST[equiptype]"; ?></td>
</tr>
<tr>
<td><strong>Weight</strong></td>
<td><? echo "$_POST[weight]"; ?></td>
</tr>
<tr>
<td><strong>Miles</strong></td>
<td><? echo "$_POST[miles]"; ?></td>
</tr>
</table>
<p><a href="newloads.html">Add Another Record</a></p>
<p><br>
</p>
</body>
</html>
 
I would create 1 column of the type date. This way you can use the nifty MySQL functions when retrieving the data.
 
ok. but how do I grab all three variables that the user selects from the dropdown menu. $month $day $year into one column?

Thanks
 
when you write the sql statement just use the three variables as the column value; such as:
Code:
$sql = "INSERT INTO [i]table_name[/i] (order_id, order_date) VALUES
        (null, '$year:$month:$day')";
 
I appreciate the help and hate to be a pain. But i am still learning PHP/MYSql. If you look at my code, how do I id the three variables to go into a column I have named pickupdate.


The code:

<?
function make_calendar_pulldowns($m=NULL, $d=NULL, $y=NULL) {

// Make the months array.
$months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December');

/// Make the months pull-down menu.
echo '<select name="month">';
foreach ($months as $key => $value) {
echo "<option value=\"$key\"";
if ($key == $m) { // Preselect.
echo ' selected="selected"';
}
echo ">$value</option>\n";
}
echo '</select>';

// Make the days pull-down menu.
echo '<select name="day">';
for ($day = 1; $day <= 31; $day++) {
echo "<option value=\"$day\"";
if($day==$d) {//Preselect.
echo 'selected="selected"';
}
echo ">$day</option>\n";
}
echo '</select>';

// Make the years pull-down menu.
echo '<select name="year">';
for($year = 2006; $year <=2015; $year++) {
echo "<option value=\"$year\"";
if ($year == $y) {//Preselect.
echo 'selected="selected"';
}
echo ">$year</option>\n";
}
echo '</select>';
} //End of the function definition.

// Get today's information and call the function.
$dates=getdate();
make_calendar_pulldowns
($dates['mon'], $dates['mday'], $dates['year']);
?>
 
I'm not having much success with the way I was told to post the variables into one date column. Am I doint this wrong?

'$_POST[$year:$month:$day]'

Thanks again for your help


Code:
// create query
    $query = "INSERT INTO $table_name (shipperorg, pickupdate, origincity, originstate, destcity, deststate, loadtype, equiptype, weight, miles) VALUES ('$_POST[shipperorg]', '$_POST[$year:$month:$day]', '$_POST[origincity]', '$_POST[originstate]', '$_POST[destcity]', '$_POST[deststate]', '$_POST[loadtype]', '$_POST[equiptype]', '$_POST[weight]', '$_POST[miles]')";
 
oh . i dont think that is what was meant. you need to read up on escaping and cleaning user input but a quick fix for the sample you are working on is

Code:
    $query = "INSERT INTO $table_name (shipperorg, pickupdate, origincity, originstate, destcity, deststate, loadtype, equiptype, weight, miles) VALUES ('$_POST[shipperorg]', '".$_POST["year"].":".$_POST['month'].":".$_POST['day']."', '$_POST[origincity]', '$_POST[originstate]', '$_POST[destcity]', '$_POST[deststate]', '$_POST[loadtype]', '$_POST[equiptype]', '$_POST[weight]', '$_POST[miles]')";

ideally you would run something like the following as a minimum:
Code:
foreach ($_POST as &$val):
 $val = mysql_escape_string(trim($val));
endforeach;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top