Guest Posted April 5, 2011 Share Posted April 5, 2011 The attached code works but I have one issue. When I type in a date for the fields "Submitted to Office" or "Submitted to Supervisor" in the format 2011-05-05 & then click the submit button, it gets entered into my MySQL databse correctly. My question is, is there any way to edit this code so the user will get a pop up box if the enter a date other than in the format YYYY-MM-DD? Basically, I want them to enter it as YYYY-MM-DD so it will update the MySQl database like it is supposed to. <b> <p> <i> To go to the main page <a href="http://tnep-g-psrflow/flow/index.html">click here</a>.</p> </i> <?php # edit_dqa.php $page_title = 'Edit a Record'; $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("psrflow", $con); ini_set('display_errors',1); error_reporting(E_ALL); if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { $id = $_GET['id']; } elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { $id = $_POST['id']; } else { // No valid ID, kill the script. echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; include ('./includes/footer.html'); exit(); } if (isset($_POST['submitted'])) { $errors = array(); if (empty($_POST['pacts'])) { $errors[] = 'You forgot to enter your PACTS number. If there is no PACTS # you can enter 0000'; } else { $pt = $_POST['pacts']; } if (empty($_POST['fname'])) { $errors[] = 'You forgot to enter the first name.'; } else { $fn = $_POST['fname']; } if (empty($_POST['lname'])) { $errors[] = 'You forgot to enter the last name.'; } else { $ln = $_POST['lname']; } if (empty($_POST['date_sub_crt'])) { $errors[] = 'You forgot to enter a date submitted to office!.'; } else { $crt = $_POST['date_sub_crt']; } if (empty($_POST['date_disclo_att'])) { $errors[] = 'You forgot to enter the supervisor disclosure date!'; } else { $disc = $_POST['date_disclo_att']; } if (empty($errors)) { $query = "UPDATE psrinfo SET pacts='$pt', fname='$fn', lname='$ln', date_sub_crt='$crt', date_disclo_att='$disc' WHERE fid=$id"; $result = @mysql_query ($query); // Run the query. $EmailAddress = '[email protected]'; $Message = "A clerk has entered a 'Date Submitted to supervisor or office'. Please enter/edit this information in PACTS.\n \n PACTS No : ${_REQUEST['pacts']}\n First Name : ${_REQUEST['fname']} \n Last Name : ${_REQUEST['lname']} \n Date Submitted to office : ${_REQUEST['date_sub_crt']} \n Date Dislosed to supervisor : ${_REQUEST['date_disclo_att']} "; $Subject = "A Clerk has Edited a Record."; $Headers = "From: [email protected] \n"; if (mail($EmailAddress, $Subject, $Message, $Headers)) { echo "<p><center><h2>My Office</h2></center></p>"; echo "<p><h3><center>Eastern District</center></h3></p>"; echo "<center>An email has been sent to your supervisor for approval and "; } else { echo "This system is not working properly. Please contact IT so they can fix it."; } $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); if ((substr($url, -1) == '/') OR (substr($url, -1) == '//')) { $url = substr ($url, 0, -1); } $url ='/flow/index.html'; header("Location: $url"); exit(); } else { // Report the errors. echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred:<br />'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } } $query = "SELECT pacts, fname, lname, date_sub_crt, date_disclo_att, date_disclo_att FROM psrinfo WHERE fid = " . $_REQUEST['id']; $result = @mysql_query ($query); // Run the query. if (mysql_num_rows($result) == 1) { $row = mysql_fetch_array ($result, MYSQL_NUM); ?> <?php echo '<form action="clerk_edit.php" method="post"> <fieldset><legend><h2> You are editing a record! After submitting this form, your DQA will be notified of the change via email.</h2></legend> <b>PACTS No:</b> <br><input type="text" name="pacts" size="15" maxlength="30" value="'.$row[0].'" /><br> <b>First Name:</b> <br><input type="text" name="fname" size="15" maxlength="30" value="'.$row[1].'" /><br /> <b>Last Name:</b> <br><input type="text" name="lname" size="15" maxlength="30" value="'.$row[2].'" /><br /> <b>Submitted to office: </b><br><input type="text" name="date_sub_crt" size="15" maxlength="30" value="'.$row[3].'" /> <br> <b>Submitted to supervisor: </b><br><input type="text" name="date_disclo_att" size="15" maxlength="30" value="'.$row[4].'" /> <br> </fieldset> <div align="left"><input type="submit" name="submit" value="Submit" /></div> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="id" value="' . $id . '" /> </form>'; } else { // Not a valid user ID. echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed in error.</p><p><br /><br /></p>'; } mysql_close(); // Close the database connection. ?> Quote Link to comment https://forums.phpfreaks.com/topic/232776-code-help-requested/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 5, 2011 Share Posted April 5, 2011 Don't give the visitor a choice of how the value gets entered, either use a pop-up date-picker that supplies the YYYY-MM-DD format and/or use three individual drop-down-select lists, one for year, one for month, and one for the day. Quote Link to comment https://forums.phpfreaks.com/topic/232776-code-help-requested/#findComment-1197317 Share on other sites More sharing options...
Guest Posted April 5, 2011 Share Posted April 5, 2011 That would be neat....I have no clue how to use a date picker...could I see some sample code? Quote Link to comment https://forums.phpfreaks.com/topic/232776-code-help-requested/#findComment-1197322 Share on other sites More sharing options...
Guest Posted April 5, 2011 Share Posted April 5, 2011 Here's the code that checks to make sure something is entered & not left blank.....can I do something similair to this code to make sure the date is enetered in the YYYY-MM-DD format? if (empty($_POST['date_disclo_att'])) { $errors[] = 'You forgot to enter the date!'; } else { $disc = $_POST['date_disclo_att']; } Quote Link to comment https://forums.phpfreaks.com/topic/232776-code-help-requested/#findComment-1197330 Share on other sites More sharing options...
PFMaBiSmAd Posted April 5, 2011 Share Posted April 5, 2011 http://dynamicdrive.com/dynamicindex7/jasoncalendar.htm Quote Link to comment https://forums.phpfreaks.com/topic/232776-code-help-requested/#findComment-1197339 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.