My SQL table is as follows:
$sql= "CREATE TABLE EMPLOYEE(
ID INT(3) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(20) NOT NULL,
Date DATE,
Age INT(3) NOT NULL
)";
I need to find the age by finding difference between the current date and input date. The problem is that when I use the following code:
$sql1="SELECT CURDATE()";
$sql=$conn->query($sql1); //$conn is DB connection variable
if($sql)
{
while($row=mysql_fetch_array($sql))
{
echo $row['CURDATE()'] ;
}
}
It gives this error:
mysql_fetch_array() expects parameter 1 to be resource, object given.
I am fairly new to PHP using DB and need help to get things around. I would be obliged if I can also get help through working code in calculating the age. This refers to querying date from DB, finding difference in years and storing it back in DB in age field.
Please don't close this question as DUPLICATE as I was not able to get my doubts cleared with posts of other users.