user1479534
user1479534

Reputation:

facebook registration birthday mysql returning 0000-00-00

I have 1 problem to fix with my facebook registration plugin for a website. im trying to insert the birthday into the db, facebook format is dd-mm-yyyy...im getting a result 0000-00-00,

<code>
$sql = "INSERT INTO users(facebook, 
                          email, 
                          username, 
                          country, 
                          gender, 
                          dob,
                          password, 
                          profile, 
                          activated, 
                          ip)
        VALUES(?, ?, ?, ?, ?, ?, ?, 'images/default_profile.png', 1,  ? 

$data = array($fbId, $register['email'],
                     $register['username'],
                     $location,
                     $register['gender'],
                     $register['birthday'],
                     md5($register['password']),
                     $_SERVER['REMOTE_ADDR']
             );

any help would be great, thanks

Upvotes: 1

Views: 476

Answers (2)

ifaour
ifaour

Reputation: 38135

You need to correctly format the date. In one of my previous tutorials, I used something like this (hopefully it's still working):

$fb_birthday = date("Y-m-d" , strtotime($fb_birthday));

Upvotes: 1

Ray
Ray

Reputation: 41438

Yes, for MySQL you have to submit it as a string in 'YYYY-MM-DD' format, if it's not it's treated as in invalid entry and the field gets set to '0000-00-00' Convert it in php before sending. If you're sure of the format from Facebook is always dd-mm-yyyy I'd just explode the string on the dash separator and rearrange the order of values.

$fbDate =  $register['birthday'];
$dateArray = explode("-", $fbDate);

$newDate = $dateArray[2]."-".$dateArray[1]."-".$dateArray[0];

Then use the $newDate in your data array for the prepared statement.

$data = array($fbId, $register['email'],
                 $register['username'],
                 $location,
                 $register['gender'],
                 $newDate,
                 md5($register['password']),
                 $_SERVER['REMOTE_ADDR']
         );

Upvotes: 0

Related Questions