我有一个脚本来回复发送邮件的用户,当我使用回复脚本时,它没有在数据库中存储任何名称。
以下是为回复设置会话的查看脚本。
$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>';
}
然后回复的脚本:
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);
答案 0 :(得分:0)
您正在定义$username2
,但在查询中使用$username
。
答案 1 :(得分:0)
正如@albxn所说,
由于sqlquery中有'from'
,因此不会填充 $username
但是,您正试图从'to'
$_SESSION['reply'];
你没有session_start()