j33baS Posted January 30, 2008 Share Posted January 30, 2008 I have the following code ... <?php if($_POST['submit']) { $validdate = checkdate($_POST['month'], $_POST['day'], $_POST['year']); if($validdate == TRUE) { $concatdate = $_POST['year'] . "-" . sprintf("%02d", $_POST['day']) . "-" . sprintf("%02d", $_POST['month']); $datesql = "INSERT INTO test(date) VALUES($concatdate);"; mysql_query($datesql); header("Location: " . $config_basedir . "/success.php"); } else { echo "date error"; } } else { require("header2.php"); } ?> <h2>Add New date</h2> <!-- ******** Date selector ******** --> <form method="post"> <table> <tr> <td>Day</td> <td>Month</td> <td>Year</td> </tr> <tr> <td> <select name="day"> <?php for($i=1;$i<=31;$i++){ echo "<option>" . $i . "</option>"; } ?> </select> </td> <td> <select name="month"> <?php for($i=1;$i<=12;$i++){ echo "<option>" . $i . "</option>"; } ?> </select> </td> <td> <select name="year"> <?php for($i=2008;$i<=2020;$i++){ echo "<option>" . $i . "</option>"; } ?> </select> </td> <td><input type="submit" name="submit" value="Go"></td> </tr> </table> </form> <!-- ******** END Date selector ******** --> <!-- ******** VIEW DATE ******** --> <?php //NOW() $titlequery = "SELECT * FROM test ORDER BY date DESC"; $titleresult = mysql_query($titlequery); while($row = mysql_fetch_array($titleresult)){ echo "<p>"; echo date("D jS F Y",strtotime($row['date'])); echo "</p>"; } ?> but theres a problem when the selected date is inserted into the database (test, which only has fields date(type date and id which is auto incrementing and the PK) and all thats being inserted is 0000-00-00. $concatdate should be inserting it as mysql's favorite YYYY-MM-DD format with the code for leading zero's and the hyphens in there as well! Was wondering if anyone could see any glaring errors ?! thanks Quote Link to comment https://forums.phpfreaks.com/topic/88543-solved-insert-into-problem-with-dates/ Share on other sites More sharing options...
neilfurry Posted January 30, 2008 Share Posted January 30, 2008 hi, could you pls try replacing this line : $datesql = "INSERT INTO test(date) VALUES($concatdate);"; with this one $datesql = "INSERT INTO test (date) VALUES('$concatdate')"; Quote Link to comment https://forums.phpfreaks.com/topic/88543-solved-insert-into-problem-with-dates/#findComment-453308 Share on other sites More sharing options...
j33baS Posted January 30, 2008 Author Share Posted January 30, 2008 yea man, i was just gona say i figured it out ! cheers anyway, im always doin stuff like this thanks Quote Link to comment https://forums.phpfreaks.com/topic/88543-solved-insert-into-problem-with-dates/#findComment-453329 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.