gpt4 book ai didi

php - 如何从 mysql 回显日期(数字)

转载 作者:行者123 更新时间:2023-11-30 22:12:40 25 4
gpt4 key购买 nike

我想学习 php 和 html,所以我正在制作素描网站。我想知道如何使用 echo 语句。

我有这个代码

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

但它只显示 $_Session[username]。 Trn_date 显示空白。

这是我的mysql的代码。

  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`)

);

编辑

    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:已解决,但它显示相同的日期。

 $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

最佳答案

好的,在回显你的日期变量之前创建

注意:- 您必须在回显之前定义此变量。

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

创建此日期变量后,现在在您打招呼时回显此变量。

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

从数据库中获取数据

//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;

希望这能解决您的问题。

关于php - 如何从 mysql 回显日期(数字),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39545530/

25 4 0