Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > PHP

Reply
 
LinkBack Thread Tools
Old November 21st, 2008, 11:15 AM   #1
New Member
 

Join Date: Nov 2008
Location: Singapore
Posts: 20
Thanks: 4
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 scorptique is on a distinguished road
[solved] Inserting date form into database

Hello,
I created a form. A drop down list for the person to select his date-of-birth, YYYY-MM-DD, then add it into the database with all his other particulars.

Problem is, I dont know how to insert the date. Because in my database, it will show 0000-00-00.

This is my code to select the DOB from 3 drop down menus.
Code:
 <?php
         
echo "<select name='day'>";
 for (
$x=1$x<=31$x++) {
  echo 
"<option value=$x>$x</option>";
 }
 echo 
"</select>";
 
 echo 
"<select name='month'>";
 for (
$x=1$x<=12$x++) {
  echo 
"<option value=$x>$x</option>";
 }
 echo 
"</select>";
 
 echo 
"<select name='year'>";
 for (
$x=2008$x>=1930$x--) {
  echo 
"<option value=$x>  $x  </option>";} 
 echo 
"</select>";
  
?>

Code:
<?php
$day 
$_POST['day'];
 
$month $_POST['month'];
 
$year $_POST['year'];
 
//my attempt to convert a single digit into double digits for the month and day 1-9
if($month && $month <10){$month '0' $month;}
 if(
$day && $day 10){$day '0' $day;}
 
$dob $year."-".$month."-".$day;
?>
Code:
     //Prepare the Insert Statement
     
$stmt $mysqli->prepare("INSERT INTO User 
     VALUES (?,?,?,?,?,?)"
);
     
//Bind the values
     //I think the "d" in "sdssss" should stand for date right?
     
$stmt->bind_param("sdssss"$email$dob$password$fname
     
$lname$gender); 
When I used command prompt to check my DOB, they were all 0000-00-00. Help please! =/

Last edited by scorptique; November 21st, 2008 at 11:40 AM..
scorptique is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 21st, 2008, 11:37 AM   #2
New Member
 

Join Date: Nov 2008
Location: Singapore
Posts: 20
Thanks: 4
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 scorptique is on a distinguished road
Re: Inserting date form into database

Oops. Sorry guys, hope I didnt waste your time. I solved it already. ^^;;;
It's suppose to be "ssssss" not "sdssss".

Last edited by scorptique; November 21st, 2008 at 11:38 AM.. Reason: Solved
scorptique is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
database , date , form , insert


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
changing the date output from a database to display today, yesterday etc ljackson84 PHP 5 September 25th, 2008 05:48 PM
ASP form to check weather a form value is already in the database Andrew1986 Classic ASP 3 October 25th, 2007 04:23 AM
Inserting Session into the database franknu PHP 11 June 16th, 2007 08:16 PM
Inserting an array into a database. Gup Classic ASP 2 August 10th, 2006 04:49 AM
database retrieval by date Lizard- Classic ASP 3 August 9th, 2004 09:28 AM


Search Engine Optimization by vBSEO 3.2.0 RC8