[英]Reply script not storing name in Database
I have a script to reply to a user that sent a message, and it is not storing any name in the database when i use the reply script. 我有一个脚本来回复发送邮件的用户,当我使用回复脚本时,它不在数据库中存储任何名称。
Here's the viewing script that sets the session for the reply. 这是设置答复会话的查看脚本。
$query = "SELECT `to`, `from`, rank, gender, picture, title, msg FROM kaoscraft_pm WHERE `to` = '$username1' ORDER BY msg_id DESC";
$data = mysqli_query($dbc, $query);
$gender = $row['gender'];
while ($row = mysqli_fetch_array($data)) {
$_SESSION['reply'] = $row['from'];
$username2 = $_SESSION['reply'];
echo '<div class="viewpost">';
echo '<div class="vpside">';
if(!empty($row['picture'])) {
echo '<img class="pictest" src="' . MM_UPLOADPATH . $row['picture'] . '" alt="' . MM_UPLOADPATH . 'nopic.png' . '" />';
}
if(!empty($row['from'])) {
echo '<p>From:<br />' . $row['from'] . '</p>';
echo '<a href="reply.php">Reply</a>';
}
And then the script for the reply: 然后是用于回复的脚本:
if (isset($_POST['submit'])) {
$username2 = $_SESSION['reply'];
// Grab the profile data from the POST
$msg = mysqli_real_escape_string($dbc, strip_tags( trim($_POST['msg'])));
$title = mysqli_real_escape_string($dbc, trim($_POST['title']));
$to = $username2;
// Update the post data in the database
if (!empty($msg) && !empty($title)) {
// Only set the picture column if there is a new picture
$query = "INSERT INTO kaoscraft_pm (`from`, `to`, `rank`, `gender`, `picture`, `msg_date`, `title`, `msg`) VALUES ('$username', '$to', '$rank', '$gender', '$picture', NOW(), '$title', '$msg')";
mysqli_query($dbc, $query);
您正在定义$username2
但随后在查询中使用$username
。
As @albxn says, 正如@albxn所说,
'from'
will not be populated as you have $username
in the sqlquery 因为您在sqlquery中有
$username
,所以不会填充'from'
but also, you're trying to populate 'to'
from $_SESSION['reply'];
而且,您也尝试从
$_SESSION['reply'];
填充'to'
$_SESSION['reply'];
and you didn't do a session_start()
而且您没有执行
session_start()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.