Alx Tioltisan Alx Tioltisan - 2 months ago 9
MySQL Question

How to echo the date (numbers) from mysql

I want to learn php & html so I'm making sketch websites. I want to know how to use echo statement.

I have this code

Welcome, <?php echo $_SESSION['username']; ?> !
Today's date is: <?php echo $_SESSION['trn_date']; ?>


But only $_Session[username] it's showing. Trn_date shows blank.

This is my mysql's code.

CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`trn_date` datetime NOT NULL,
PRIMARY KEY (`id`)


);

EDIT

require('db.php');
// If form submitted, insert values into the database.
if (isset($_POST['username'])){
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$username = stripslashes($username);
$username = mysql_real_escape_string($username);
$email = stripslashes($email);
$email = mysql_real_escape_string($email);
$password = stripslashes($password);
$password = mysql_real_escape_string($password);
$trn_date = date("Y-m-d H:i:s");
$query = "INSERT into `users` (username, password, email, trn_date) VALUES ('$username', '".md5($password)."', '$email', '$trn_date')";
$result = mysql_query($query);


EDIT2: RESOLVED, BUT IT SHOWS ME THE SAME DATES.

$antrenor = date("Y-m-d");
$PrimulContract = date("Y-m-d");
$ExpiraContract = date("Y-m-d");?>


Welcome <?php echo $_SESSION['username']; ?> !
Your subscribe will end in the date <?php echo $ExpiraContract; ?>
You've subscribed at : <?php echo $PrimulContract; ?>
On the date <?php echo $antrenor; ?> you will receive a new mail

Answer

Ok, Before echoing your date variable create

Note:- You have to define this variable before echoing it.

$date_today = date("Y-m-d H:i:s");

After creating this date variable now echo this variable when you are greeting.

Welcome, <?php echo $_SESSION['username']; ?> !
Today's date is: <?php echo $date_today; ?> 

Fetch data from database

//fetch from database 
    $sql = mysqli_query($connection_name, "SELECT * FROM username WHERE username = '$usename' LIMIT 1");
    while($row = mysqli_fetch_array($sql)){

                $db_username = $row['username']; 
                $db_email = $row['email'];
                $db_expire = $row['expire_date'];
                $antrenor = $row['antrenor'];
                $primulContract = $row['primulContract'];
            }
    //Now you can echo these details if you want 

    // to show Expire Date you have to echo 
    echo $db_expire;

Hope this will solve your problem.