flashbangpro Posted September 3, 2012 Share Posted September 3, 2012 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 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="<select name=\"".$name."month\">"; for($i=1;$i<=12;$i++) { $html.="<option value='$i'>$months[$i]</option>"; } $html.="</select> "; // Day dropdown $html.="<select name=\"".$name."day\">"; for($i=1;$i<=31;$i++) { $html.="<option $selected value='$i'>$i</option>"; } $html.="</select> "; // Year dropdown $html.="<select name=\"".$name."year\">"; for($i=$startyear;$i<=$endyear;$i++) { $html.="<option value='$i'>$i</option>"; } $html.="</select> "; return $html; } ?> Maintenance Form - <?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 "<table border='1'> <tr> <th>Vehicle Name</th> <th>Vehicle Number </th> <th>Issue Comments </th> </tr>"; while($row = mysql_fetch_array($result1)) { echo "<tr>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['number'] . "</td>"; echo "<td>" . $row['issue_comments'] . "</td>"; echo "</tr>"; } echo "</table>"; ?> <html> <body> <h1>Maintenace Repair Form </h1> <section> <section> <form method="post" name="form1" action="updated_maint.php"> <table align="center"> <tr valign="baseline"> <th nowrap align="right">Issue Being Reported:</th> <td><select name="issues_reported" > <option value=""></option> <option value="Engine">Engine</option> <option value="Transmission">Transmission</option> <option value="Differential">Differential</option> <option value="Electrical">Electrical</option> <option value="Tires">Tires</option> <option value="Brakes">Brakes</option> <option value="HVAC">HVAC</option> <option value="Lighting">Lighting</option> <option value="Accident">Accident</option></select></td> </tr> <tr valign="baseline"> <th nowrap align="right">Date That Maintenace/Repair Issues Reported:</th> <td> <?php echo date_picker("date_reported")?></td> </tr> <tr valign="baseline"> <th nowrap align="right">Scheduled Service Date:</th> <td> <input type="text" name="service_date" value="" size="32"></td> </tr> <tr valign="baseline"> <th nowrap align="right">Maintenace/Repair Service Performed W/Comments:</th> <td> <textarea name="service_performed" rows="3" cols="27"></textarea></td> </tr> <tr valign="baseline"> <th nowrap align="right">Status:</th> <td><select name="status" > <option value=""></option> <option value="In Service">In Service</option> <option value="Out of Service">Out of Service</option> <option value="In Service Repair Pending">In Service Repair Pending</option> </select></td> </tr> <tr valign="baseline"> <th nowrap align="right">Date Maintenace/Repair Service Performed:</th> <td><input type="text" name="date_service_performed" value="" size="32"></td> </tr> <tr valign="baseline"> <th nowrap align="right">Date OF Follow-up Work / If Needed:</th> <td> <input type="text" name="date_of_followup" value="" size="32"></td> </tr> <tr valign="baseline"> <th nowrap align="right">Service In Progress:</th> <td><select name="service_in_progress" > <option value=""></option> <option value="Yes">Yes</option> <option value="No">No</option> </select></td> </tr> <tr valign="baseline"> <th nowrap align="right">Projected Date Return To Use:</th> <td> <input type="text" name="date_return_use" value="" size="32"></td> </tr> <tr valign="baseline"> <th nowrap align="right">Projected Time Return Use:</th> <td> <input type="text" name="time_return_use" value="" size="32"></td> </tr> <tr valign="baseline"> <th nowrap align="right">Actual RTS:</th> <td> <input type="text" name="rts" value="" size="32"></td> </tr> <tr valign="baseline"> <th nowrap align="right">Odometer Reading:</th> <td> <input type="text" name="odomread" value="" size="32"></td> </tr> <tr valign="baseline"> <th nowrap align="right">Date Of Odometer Reading:</th> <td><input type="text" name="odomdate" value="" size="32"></td> </tr> <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> <!-- end .content --></h2> </section> </body> </html> Update File - <?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 "<p>Maintenance Info Creation Failed.</p>"; echo "<p>" . mysql_error() . "</p>"; } echo "<p>Error: " . mysql_error() . " SQL: $query</p>"; ?> Thank you, any help or suggestions are appreciated. Quote Link to comment Share on other sites More sharing options...
Spring Posted September 3, 2012 Share Posted September 3, 2012 What errors are you getting? Quote Link to comment Share on other sites More sharing options...
flashbangpro Posted September 3, 2012 Author Share Posted September 3, 2012 Its not showing any errors and updates all fields I enter data into except the date field I am using the date picker with. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 3, 2012 Share Posted September 3, 2012 Echo your query string and see if it contains the values you'd expect it to contain. Quote Link to comment Share on other sites More sharing options...
flashbangpro Posted September 3, 2012 Author Share Posted September 3, 2012 Do I echo query string by taking out the redirect and adding <?php echo $_SERVER['QUERY_STRING']; ?> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 3, 2012 Share Posted September 3, 2012 Do you know what a database query string is? Quote Link to comment Share on other sites More sharing options...
Barand Posted September 3, 2012 Share Posted September 3, 2012 In other words echo $query; What does this give? Quote Link to comment Share on other sites More sharing options...
flashbangpro Posted September 3, 2012 Author Share Posted September 3, 2012 Here is what it gave me - Notice: Undefined index: date_reported in /data/9/0/28/4/517493/user/528148/htdocs/jednewdb/updated_maint.php on line 11 UPDATE service_info SET `service_date`='', `date_reported`='', `issues_reported`='', `service_performed`='', `rts`='', `odomread`='', `odomdate`='', `status`='', `date_service_performed`='', `date_of_followup`='',`service_in_progress`='', `date_return_use`='', `time_return_use`='', `issues_nonrepairable`='', `date_nonrepairable_issues`='', `comments` ='' WHERE id='73' Line 11 is $date_reported = mysql_prep($_POST['date_reported']); Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 3, 2012 Share Posted September 3, 2012 You don't have a date_reported field in your form. Quote Link to comment Share on other sites More sharing options...
flashbangpro Posted September 3, 2012 Author Share Posted September 3, 2012 Isn't this a date_reported field? <tr valign="baseline"> <th nowrap align="right">Date That Maintenace/Repair Issues Reported:</th> <td> <?php echo date_picker("date_reported")?></td> </tr> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.