简体   繁体   English

回复脚本未在数据库中存储名称

[英]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.

相关问题 将图像文件名存储在db中并将实际文件存储在服务器中vs将图像数据存储在数据库中并使用脚本加载图像 - Storing image file name in db and actual file in server vs Storing image data in database and loading the image with script. 如何从Java脚本回复按钮获取值到数据库? - How to get value from java script reply button into database? Fileupload在php中不起作用并且不在数据库中存储名称 - Fileupload Not Working in php and not storing name in database 将图像存储在数据库中具有唯一名称和路径的文件夹中 - Storing the image in folder with unique name and path in database PHP&MySQL数据库存储名称数组问题 - PHP & MySQL database storing the name Array problem 将ID存储到数据库表中时会在该处抛出名称 - Storing id into database table throw there name 使用Codeigniter将HTML标记(包括PHP脚本)存储在数据库中 - Storing HTML tags including PHP script in the database using Codeigniter 自动添加复选框值并保留其名称以存储在数据库中 - Auto add checkbox values and keep their name for storing in database Laravel Nova 在数据库和本地存储中存储原始文件名 - Laravel Nova storing original file name in the database and in local storage PHP脚本,用于通知客户端名称是否在数据库中 - PHP Script to inform client if name is in a database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM