PHP date picker not updating MySQL table

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 ""; while($row = mysql_fetch_array($result1)) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
Vehicle Name Vehicle Number Issue Comments
" . $row['name'] . "" . $row['number'] . "" . $row['issue_comments'] . "
"; ?>

Maintenace Repair Form

         <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">&nbsp;</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>&nbsp;</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.

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:

first off see if your session is working because it doesnt look like you are making a session id try this maybe

[php]

$id=session_id();

[/php]

that will give an id at least and you can go from there

is there also a sql input when a person goes on our site first so they can get a session id in the database

The Session is working because I can change the date field back to a text field and update all the other fields without a problem.

ok so now is it that the session isnt being inserted into the database when the user connects

// get value of id that sent from address bar $id=$_GET['id']; $_SESSION['id'] = $id; echo $id;

doesnt give a session id

// get value of id that sent from address bar

$id=session_id();

echo $id;

but this does

does the session id get passed from somewhere else

The session id worked fine, the only thing I changed was the date picker.

right but in your sql where clause statement it i looking for the session id is that id going into the database to be checked

Sponsor our Newsletter | Privacy Policy | Terms of Service