I am wanting to have a drop down date picker on my maintenance vehicle update forms.
The date picker shows up and allows you to choose a date, but it does not insert/update any information in the MySQL database table. I’m wanting to do this to all my date fields but as of now I’m just testing on the first date field in the form.
Here is the code I am working with
Functions file -
[php]
<?php
function date_picker($name, $startyear=NULL, $endyear=NULL)
{
if($startyear==NULL) $startyear = date("Y")-100;
if($endyear==NULL) $endyear=date("Y")+50;
$months=array('','January','February','March','April','May',
'June','July','August', 'September','October','November','December');
// Month dropdown
$html="";
for($i=1;$i<=12;$i++)
{
$html.="$months[$i]";
}
$html.=" ";
// Day dropdown
$html.="";
for($i=1;$i<=31;$i++)
{
$html.="$i";
}
$html.=" ";
// Year dropdown
$html.="";
for($i=$startyear;$i<=$endyear;$i++)
{
$html.="$i";
}
$html.=" ";
return $html;
}
?>[/php]
Maintenance Form -
[php]<?php session_start();?>
<?php require_once("dbcon.php"); ?>
<?php require_once("functions.php"); ?>
<?php
// get value of id that sent from address bar
$id=$_GET['id'];
$_SESSION['id'] = $id;
// Retrieve data from database
$sql="SELECT * FROM service_info WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
$result1 = mysql_query("SELECT name, number, issue_comments FROM service_info WHERE id='$id'");
echo "
Vehicle Name |
Vehicle Number |
Issue Comments |
";
while($row = mysql_fetch_array($result1))
{
echo "";
echo "" . $row['name'] . " | ";
echo "" . $row['number'] . " | ";
echo "" . $row['issue_comments'] . " | ";
echo "
";
}
echo "
";
?>
Maintenace Repair Form
Issue Being Reported: |
Engine
Transmission
Differential
Electrical
Tires
Brakes
HVAC
Lighting
Accident |
Date That Maintenace/Repair Issues Reported: |
<?php echo date_picker("date_reported")?> |
Scheduled Service Date: |
|
Maintenace/Repair Service Performed W/Comments: |
|
Status: |
In Service
Out of Service
In Service Repair Pending
|
Date Maintenace/Repair Service Performed: |
|
Date OF Follow-up Work / If Needed: |
|
Service In Progress: |
Yes
No
|
Projected Date Return To Use: |
|
Projected Time Return Use: |
|
Actual RTS: |
|
Odometer Reading: |
|
Date Of Odometer Reading: |
|
<tr valign="baseline">
<th nowrap align="right">Nonrepairable Issues Found W/Comments:</th>
<td>
<textarea name="issues_nonrepairable" rows="3" cols="27"></textarea></td>
</tr>
<tr valign="baseline">
<th nowrap align="right">Date Nonrepairable Issues Found:</th>
<td>
<input type="text" name="date_nonrepairable_issues" value="" size="32"></td>
</tr>
<tr valign="baseline">
<th nowrap align="right">Repair Made:</th>
<td>
<textarea name="comments" rows="3" cols="27"></textarea></td>
</tr>
<input type="hidden" name="id" value = "$id" />
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Insert record"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<a href="service_list_update.php">Cancel</a>
<p> </p>
</section>
</section>
[/php]
Update File -
[php]<?php
ini_set(‘display_errors’,1);
error_reporting(E_ALL);
?>
<?php session_start();?>
<?php require_once("dbcon.php"); ?>
<?php require_once("functions.php"); ?>
<?php
$id = $_SESSION['id'];
$service_date = mysql_prep($_POST['service_date']);
$date_reported = mysql_prep($_POST['date_reported']);
$issues_reported = mysql_prep($_POST['issues_reported']);
$service_performed = mysql_prep($_POST['service_performed']);
$status = mysql_prep($_POST['status']);
$date_service_performed = mysql_prep($_POST['date_service_performed']);
$date_of_followup = mysql_prep($_POST['date_of_followup']);
$service_in_progress = mysql_prep($_POST['service_in_progress']);
$rts = mysql_prep($_POST['rts']);
$odomread = mysql_prep($_POST['odomread']);
$odomdate = mysql_prep($_POST['odomdate']);
$date_return_use = mysql_prep($_POST['date_return_use']);
$time_return_use = mysql_prep($_POST['time_return_use']);
$issues_nonrepairable = mysql_prep($_POST['issues_nonrepairable']);
$date_nonrepairable_issues = mysql_prep($_POST['date_nonrepairable_issues']);
$comments = mysql_prep($_POST['comments']);
?>
<?php
$query = "UPDATE service_info SET `service_date`='$service_date', `date_reported`='$date_reported',
`issues_reported`='$issues_reported', `service_performed`='$service_performed', `rts`='$rts', `odomread`='$odomread', `odomdate`='$odomdate', `status`='$status', `date_service_performed`='$date_service_performed',
`date_of_followup`='$date_of_followup',`service_in_progress`='$service_in_progress', `date_return_use`='$date_return_use', `time_return_use`='$time_return_use',
`issues_nonrepairable`='$issues_nonrepairable', `date_nonrepairable_issues`='$date_nonrepairable_issues', `comments` ='$comments'
WHERE id='$id' ";
$result = mysql_query($query, $connection);
if ($result) {
// Success!
redirect_to("service_list_update.php");
} else {
// Display error message.
echo "Maintenance Info Creation Failed.
";
echo "" . mysql_error() . "
";
}
echo "Error: " . mysql_error() . " SQL: $query
";
?>
[/php]
Thank you, any help or suggestions are appreciated.