Jump to content

inserting date into database


Recommended Posts

hi there

wonder if anyone can point me in the right direction with this one. I want to create a form where a user enters the date of an event. at present the only way i can manage this is if i get the user to enter todays date in a text box as (eg todays date) 20051227 which is sure going to confuse people.

What i'm wondering is how complex a procedure, taking into account my noobie status, would it be to enter the date into one columns of a database using three drop down menus. Any help much appreciated

thanks

Link to comment
https://forums.phpfreaks.com/topic/2371-inserting-date-into-database/
Share on other sites

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?php

[/span][span style=\"color:#007700\"]if(isset([/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'submit\'[/span][span style=\"color:#007700\"]]))

{

     [/span][span style=\"color:#0000BB\"]$month [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'month\'[/span][span style=\"color:#007700\"]];

     [/span][span style=\"color:#0000BB\"]$day [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'day\'[/span][span style=\"color:#007700\"]];

     [/span][span style=\"color:#0000BB\"]$year [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'year\'[/span][span style=\"color:#007700\"]];

 

     [/span][span style=\"color:#0000BB\"]$eventDate [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]$month [/span][span style=\"color:#007700\"]. [/span][span style=\"color:#DD0000\"]\" \" [/span][span style=\"color:#007700\"]. [/span][span style=\"color:#0000BB\"]$day [/span][span style=\"color:#007700\"]. [/span][span style=\"color:#DD0000\"]\", \" [/span][span style=\"color:#007700\"]. [/span][span style=\"color:#0000BB\"]$year[/span][span style=\"color:#007700\"];

 

     echo([/span][span style=\"color:#0000BB\"]$eventDate[/span][span style=\"color:#007700\"]);

}

else

{

[/span][span style=\"color:#0000BB\"]?>

[/span]<form action=\"[span style=\"color:#0000BB\"]<?=$_SERVER[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'PHP_SELF\'[/span][span style=\"color:#007700\"]][/span][span style=\"color:#0000BB\"]?>[/span]\" method=\"post\">

Enter Event Date: <select name=\"month\">

     <option value=\"Jan\">Jan</option>

     <option value=\"Feb\">Feb</option>

     <option value=\"Mar\">Mar</option>

     <option value=\"April\">April</option>

</select>

 

<select name=\"day\">

     <option value=\"1\">1</option>

     <option value=\"2\">2</option>

     <option value=\"3\">3</option>

     <option value=\"4\">4</option>

     <option value=\"5\">5</option>

     <option value=\"6\">6</option>

     <option value=\"7\">7</option>

</select>

 

<select name=\"year\">

     <option value=\"2005\">2005</option>

     <option value=\"2006\">2006</option>

</select>

 

<input type=\"submit\" value=\"Submit\" name=\"submit\">

</form>

[span style=\"color:#0000BB\"]<?php

[/span][span style=\"color:#007700\"]}

[/span][span style=\"color:#0000BB\"]?>[/span]

[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

 

All you have to do is concatenate all of the values of the selects. You can format it however you want.

 

Jeremy

thanks for that

the principle makes sense, just that when i pasted the code i got the following error

 

Parse error: parse error, unexpected T_VARIABLE in /home/fhlinux195/m/matthewtennant.com/user/htdocs/mainevent_1.php on line 9

 

i'm guessing i'm making a massive error. All the code belongs in the same page right??

 

thanks again

mat

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.