blackdogupya Posted March 7, 2012 Share Posted March 7, 2012 Hey Guys and Girls! I'm a bit of a noob when it comes to PHP and MySQL, so I'm hoping you can help me! I'm trying to create a form and parse the data to an MySQL database. The form code I have is as follows: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!-- jQuery --> <script type="text/javascript" src="js/jquery.js"></script> <!-- required plugins --> <script type="text/javascript" src="js/date.js"></script> <!--[if IE]><script type="text/javascript" src="scripts/jquery.bgiframe.min.js"></script><![endif]--> <!-- jquery.datePicker.js --> <script type="text/javascript" src="js/date_picker.js"></script> <!-- datePicker required styles --> <link rel="stylesheet" type="text/css" media="screen" href="css/default.css"> <script type="text/javascript" charset="utf-8"> $(function() { $('.date-pick').datePicker().dpSetSelected(new Date().asString()); }); </script> <title>POPLAF Database - Add Animal</title> </head> <body> <form method="post" action="process.php"> Status:<br> <BR /> <input type="radio" name="status" value="lost" /> Lost<br /><BR /> <input type="radio" name="status" value="found" /> Found <BR /> <BR /> Date: <br> <input name="date" id="date" class="date-pick" /> <br><br> <input type="submit" name="Submit" value="Submit"> </form> </body> </html> This part is fine. Here's the process.php code: <? // Database Connection. Change if required. $dbms = 'mysqli'; $hostname = 'localhost'; $db_user = '*******'; $database = '*******'; $db_password = '*******'; $load_extensions = ''; $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db($database,$db); if ($_SERVER['REQUEST_METHOD'] == "POST") { // the following 4 lines are needed if your server has register_globals set to Off $status = $_POST['status']; $date = $_POST['date']; $sql = "INSERT INTO animal_info (status, date) VALUES ('$status','$date')"; //declare in the order variable $result = mysql_query($sql); //order executes if($result){ echo("<br>Input data is succeed"); } else{ echo "ERROR: ".mysql_error(); } ?> <? } ?> This part also works okay! My trouble is, with getting the date correct! Whenever I submit the form, the database shows the date as 0000-00-00 and not the date entered. I'm using jQuery for the calendar and date. Any help would be appreciated! Cheers, Dave Quote Link to comment https://forums.phpfreaks.com/topic/258437-form-help/ Share on other sites More sharing options...
Drummin Posted March 7, 2012 Share Posted March 7, 2012 I'm no expert in jquery but it looks like you are not referencing the date id in your form. <script type="text/javascript" charset="utf-8"> $(function() { $('#date').datePicker().dpSetSelected(new Date().asString()); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/258437-form-help/#findComment-1324745 Share on other sites More sharing options...
AyKay47 Posted March 7, 2012 Share Posted March 7, 2012 I'm no expert in jquery but it looks like you are not referencing the date id in your form. <script type="text/javascript" charset="utf-8"> $(function() { $('#date').datePicker().dpSetSelected(new Date().asString()); }); </script> He is referencing the input field by it's class, which is fine. What format is the date being passed in? To be inserted into a DATE field, it needs to be YYYY-MM-DD Quote Link to comment https://forums.phpfreaks.com/topic/258437-form-help/#findComment-1324831 Share on other sites More sharing options...
blackdogupya Posted March 8, 2012 Author Share Posted March 8, 2012 I'm no expert in jquery but it looks like you are not referencing the date id in your form. <script type="text/javascript" charset="utf-8"> $(function() { $('#date').datePicker().dpSetSelected(new Date().asString()); }); </script> He is referencing the input field by it's class, which is fine. What format is the date being passed in? To be inserted into a DATE field, it needs to be YYYY-MM-DD I changed the code to this, as suggested by the jQuery peeps: <script type="text/javascript" charset="utf-8"> $(function() { $('.date-pick').datePicker( "option", "dateFormat", "yyyy-mm-dd").dpSetSelected(new Date().asString()); }); </script> But I might be barking up the wrong tree. Cheers, Dave Quote Link to comment https://forums.phpfreaks.com/topic/258437-form-help/#findComment-1325034 Share on other sites More sharing options...
blackdogupya Posted March 8, 2012 Author Share Posted March 8, 2012 I just changed the MySQL field to text and let it populate. There's no real reason for it to be a DATE field. Thanks for the suggestions though! Cheers, Dave Quote Link to comment https://forums.phpfreaks.com/topic/258437-form-help/#findComment-1325125 Share on other sites More sharing options...
AyKay47 Posted March 8, 2012 Share Posted March 8, 2012 this isn't really the right solution. Dates should be stored in a DATE or DATETIME type field in the database. Quote Link to comment https://forums.phpfreaks.com/topic/258437-form-help/#findComment-1325170 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.