Jump to content


Photo

inserting date into database


  • Please log in to reply
4 replies to this topic

#1 mattennant

mattennant
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 27 June 2005 - 11:20 AM

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

#2 jeremywesselman

jeremywesselman
  • Members
  • PipPipPip
  • Advanced Member
  • 154 posts
  • LocationIndependence, KY

Posted 27 June 2005 - 01:08 PM

[!--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

#3 mattennant

mattennant
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 27 June 2005 - 03:22 PM

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



#4 jeremywesselman

jeremywesselman
  • Members
  • PipPipPip
  • Advanced Member
  • 154 posts
  • LocationIndependence, KY

Posted 27 June 2005 - 04:06 PM

Yes, it all goes on the same page. I tested on my own server before I posted here and it works for me.

Jeremy

#5 mattennant

mattennant
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 28 June 2005 - 10:56 PM

weirdly some extra spaces before the variables appear to have been causing my error, all is working fine now.
Thanks a bunch




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users