...

View Full Version : Php Date



sleekfx
03-18-2004, 11:06 PM
Hi im back again i am trying to get a date to write to my database from my form. In the form i am using drop down boxes so users can select their date of birth but all it is writing to my database is 0000-00-00, can anyone look at my code and tell me what im doing wrong.

Thanks



<?php
$hostname = "localhost";
$username = "fitorfou_sleekfx"; // The username you created for this database.
$password = "password1"; // The password you created for the username.
$usertable = "date"; // The name of the table you made.
$dbName = "fitorfou_fitorfoul"; // This is the name of the database you made.
if ($submit):
MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
@mysql_select_db($dbName) or die( "Unable to select database");

$sql = "INSERT INTO $usertable (date) VALUES ('$date')";

if (mysql_query($sql)) { echo("<P>New Record Added</P>");
} else {
echo("<P>Error adding new record: " .
mysql_error() . "</P>"); }
?>

<P><A HREF="<?php echo($PHP_SELF); ?>">Add another record</A></P>
<?php else: // Enter another record?>


<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>


<SELECT name=date> <OPTION value="" selected>&nbsp;<OPTION
value=1>1<OPTION value=2>2<OPTION value=3>3<OPTION
value=4>4<OPTION value=5>5<OPTION value=6>6<OPTION
value=7>7<OPTION value=8>8<OPTION value=9>9<OPTION
value=10>10<OPTION value=11>11<OPTION value=12>12</OPTION></SELECT>
/ <SELECT name=date> <OPTION value="" selected>&nbsp;<OPTION
value=1>1<OPTION value=2>2<OPTION value=3>3<OPTION
value=4>4<OPTION value=5>5<OPTION value=6>6<OPTION
value=7>7<OPTION value=8>8<OPTION value=9>9<OPTION
value=10>10<OPTION value=11>11<OPTION value=12>12<OPTION
value=13>13<OPTION value=14>14<OPTION value=15>15<OPTION
value=16>16<OPTION value=17>17<OPTION value=18>18<OPTION
value=19>19<OPTION value=20>20<OPTION value=21>21<OPTION
value=22>22<OPTION value=23>23<OPTION value=24>24<OPTION
value=25>25<OPTION value=26>26<OPTION value=27>27<OPTION
value=28>28<OPTION value=29>29<OPTION value=30>30<OPTION
value=31>31</OPTION></SELECT> / <SELECT name=date> <OPTION
value="" selected>&nbsp;<OPTION value=1985>1985<OPTION
value=1984>1984<OPTION value=1983>1983<OPTION
value=1982>1982<OPTION value=1981>1981<OPTION
value=1980>1980<OPTION value=1979>1979<OPTION
value=1978>1978<OPTION value=1977>1977<OPTION
value=1976>1976<OPTION value=1975>1975<OPTION
value=1974>1974<OPTION value=1973>1973<OPTION
value=1972>1972<OPTION value=1971>1971<OPTION
value=1970>1970<OPTION value=1969>1969<OPTION
value=1968>1968<OPTION value=1967>1967<OPTION
value=1966>1966<OPTION value=1965>1965<OPTION
value=1964>1964<OPTION value=1963>1963<OPTION
value=1962>1962<OPTION value=1961>1961<OPTION
value=1960>1960<OPTION value=1959>1959<OPTION
value=1958>1958<OPTION value=1957>1957<OPTION
value=1956>1956<OPTION value=1955>1955<OPTION
value=1954>1954<OPTION value=1953>1953<OPTION
value=1952>1952<OPTION value=1951>1951<OPTION
value=1950>1950<OPTION value=1949>1949<OPTION
value=1948>1948<OPTION value=1947>1947<OPTION
value=1946>1946<OPTION value=1945>1945<OPTION
value=1944>1944<OPTION value=1943>1943<OPTION
value=1942>1942<OPTION value=1941>1941<OPTION
value=1940>1940<OPTION value=1939>1939<OPTION
value=1938>1938<OPTION value=1937>1937<OPTION
value=1936>1936<OPTION value=1935>1935<OPTION
value=1934>1934<OPTION value=1933>1933<OPTION
value=1932>1932<OPTION value=1931>1931<OPTION
value=1930>1930<OPTION value=1929>1929<OPTION
value=1928>1928<OPTION value=1927>1927<OPTION
value=1926>1926<OPTION value=1925>1925<OPTION
value=1924>1924<OPTION value=1923>1923<OPTION
value=1922>1922<OPTION value=1921>1921<OPTION
value=1920>1920<OPTION value=1919>1919<OPTION
value=1918>1918<OPTION value=1917>1917<OPTION
value=1916>1916<OPTION value=1915>1915<OPTION
value=1914>1914<OPTION value=1913>1913<OPTION
value=1912>1912<OPTION value=1911>1911<OPTION
value=1910>1910<OPTION value=1909>1909<OPTION
value=1908>1908<OPTION value=1907>1907<OPTION
value=1906>1906<OPTION value=1905>1905<OPTION
value=1904>1904<OPTION value=1903>1903<OPTION
value=1902>1902<OPTION value=1901>1901<OPTION
value=1900>1900</OPTION></SELECT>
<br>


<br>

<INPUT TYPE=SUBMIT NAME="submit" VALUE="SUBMIT">
</FORM>
<?php endif; ?>

rswyatt
03-18-2004, 11:14 PM
A quick look tells me that you are using the same NAME for all three areas of the date... for month you're using name DATE and day DATE and year DATE

try using a different NAME for each select - then concatenate them together..

Like...



<SELECT name=day>
<SELECT name=month>
<SELECT name=year>


obviously - with the appropriate options..

Then put it together:



$date=$_POST['year'].$_POST['month'].$_POST['day'];


or something to that effect.

sleekfx
03-19-2004, 12:49 AM
ok ive changed the dates to '$date1' '$date2'$ etc and the date type is just date in my database.

im now getting an error message saying


Error adding new record: Column count doesn't match value count at row 1


Any ideas for me?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum