Jump to content

Retrieving Birthday from database MySQL php problem


cobusbo
Go to solution Solved by Barand,

Recommended Posts

Hi, I'm recalling information from my database to show all the birthdays of the specific day but today the 30th of November 2015 I get a list of everyone who is stored in my database showing as if its their birthday. Somewhere I made a mistake my database field is DateTime

$querybd = "SELECT Username, pdob FROM Users2"; 
	 
$resultbd = mysql_query($querybd) or die(mysql_error());

$users = array();
while($rowbd = mysql_fetch_array($resultbd)){
	if (date('m-d', strtotime($rowbd['pdob'])) == date('m-d'))
$users[] = $rowbd['Username'];
	}
    $list = implode('; ', $users);
if($list == ""){}else{
echo "<br><b>Todays Birthdays: </b>" . $list . "<br>";

}

It worked fine till today

Link to comment
Share on other sites

You are using deprecated code. You need to use PDO with prepared statements or Mysqli. Why are you going through all that code when you can just get the data you want in a query?

 

SELECT column1, column2 FROM table WHERE date_column=CURDATE()

 

 

You are all over the place with upper and lowercase naming. Use all lowercase separating words with an underscore.

Edited by benanamen
Link to comment
Share on other sites

  • Solution

SELECT column1, column2 FROM table WHERE date_column=CURDATE()

That will only get those who were born today, not whose birthday falls today.

 

SELECT username
, pdob
, YEAR(CURDATE())-YEAR(pdob) as age
FROM table
WHERE MONTH(pdob)=MONTH(CURDATE()) AND DAY(pdob)=DAY(CURDATE())
  • Like 1
Link to comment
Share on other sites

benanamen's main point is probably the issue.  Probably your version of php was updated and the mysql_ functions are deprecated and have been removed entirely.  You need to either use mysqli_ or pdo, and adjust your code accordingly, but that could be a substantial undertaking, as it should effect your entire code base any place that mysql is being used.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.