我需要传递会话用户名(用于登录的用户名),这是一封电子邮件!我需要将其传递到单独的页面并将其输出到表格中,以表示已提交的评论
$ _ SESSION ['name'] = $ _POST ['name']; -发送页面以刷新时登录 $ name = ['name']-将页面发送回登录
<!-- logged in user information -->
<?php if (isset($_SESSION['email'])) : ?>
<p>Welcome you are logged in as: <strong><?php echo $_SESSION['email']; ?></strong></p>
“电子邮件”需要从“ index.php”上方的代码传递到“ reviews.php”下方的代码
<p>
<input name="product_id" value="<?php echo "$var" ?>" readonly> <!-- get value from previous page-->
<input name="track_name" value="<?php echo "$var_value" ?>" readonly> <!-- get value from previous page-->
<input name="track_name" value="<?php echo "EMAIL_HERE" ?>" readonly> <!-- get value from previous page-->
<!-- get value from previous page-->
<input type="Submit" name="Submit" value="Submit"></p>
这是一项作业,我只能使用PHP MYSQL HTML CSS
我希望在表中以$ var和$ var_value的形式回显用户名(电子邮件),然后它们应该以表格的形式相互打印
更新 使用此代码,我现在设法获得了变量值,但无法将其插入数据库
$email = $_SESSION['email'];
$sql = "INSERT INTO reviews (rating, review, track_name, product_id, email) values('$rate', '$text', '$track', '$artist', '$email')";
``''只读>```
所以更新是如何现在将其插入数据库?
答案 0 :(得分:0)
您是否尝试在reviews.php页面中使用$ _SESSION ['email']变量? 我希望您也使用CSRF令牌
答案 1 :(得分:0)
最后谢谢您的帮助
$email = $_SESSION['email'];
从会话中获取电子邮件
$email = (isset($_POST['email']) ? $_POST['email'] : null);
删除索引错误
<input name="email" value="<?php echo "$email" ?>" readonly> <!-- get value from previous page-->
显示值
$review_query = mysqli_query($result,"SELECT rating, review, email FROM reviews WHERE track_name = '$var_value' AND product_id = '$var'");
从数据库中获取
<td class='col-4 col-s-4' name='email'><?php echo $email ?></td>
输出其值