I want to use 2 jumpmenu to let users select publishing date of their document(which only year is necessary to be filled ) and then I will save it in a correct format into db and display what the user filled such as: April 2010,2010,...
here is my code but it doesn't get the date and in my database it is saved 0000-00-00:
FORM:
THE RELATED PHP CODE:
TABLE:
I also tested it with 3 jumpmenu(instea d of NULL) but it doesn't work either. what was my mistake?only date is not saved and displayed
here is my code but it doesn't get the date and in my database it is saved 0000-00-00:
FORM:
Code:
<form action="publication.php" method="post" enctype="multipart/form-data">
<table cellpadding=0 class="text" >
<tr><td>Publisher:</td>
<td><input type="text" name="publisher"></td></tr>
<tr><td>Date</td>
<td><?php
/******* building jump menu for the month********/
$today=time();
$monthName = array(1=> "January", "February", "March","April", "May", "June", "July", "August", "September", "October","November", "December");
echo "<select name='dateMO'>\n";
for ($n=1;$n<=12;$n++)
{echo "<option value=$n\n";
echo "> $monthName[$n]\n";}
echo "</select>";
//********Building jump menu for year******//
$startYr = date("Y", $today); //get the year from $today
echo "<select name='dateYr'>\n";
for ($n=$startYr-10;$n<=$startYr+1;$n++)
{echo "<option value=$n";
echo "> $n\n";}
echo "</select>\n";
$date = $_POST['dateYr']."-";
$date .= $_POST['dateMO']."-";
$date .= NULL; //to put 00 at the end of date to be saved in db correctly ?> </td></tr>
<tr><td><input type="submit" id="add" value="add" name="submit"></td> </table></form>
Code:
<?php
if (isset($_POST['publisher'])) {
$query=mysql_query("INSERT INTO publication(publisher,date)
VALUES ('{$_POST['publisher']}','$date')") or die(mysql_error());
//displaying :
$respublic= mysql_query("SELECT * FROM publication");
while($rowpublic=mysql_fetch_assoc($respublic))
{echo ($rowpublic["publisher"]). ',' . ($date);
echo '<p> </p>';}
Code:
CREATE TABLE publication(
id int unsigned NOT NULL AUTO_INCREMENT,
publisher varchar(100) NOT NULL,
date DATE NOT NULL,
PRIMARY KEY (id)
);
Comment