如何使用元标记重定向用户

时间:2018-09-04 05:44:05

标签: php

我试图让我的观点在我的论坛上发挥作用,并认为我可能需要一个唯一的列,因此决定提供一个tinyint并将默认值设置为1。如果用户提交了新主题,则应该说1,然后将回复设置为0,但是由于某种原因,当我回复主题时,它将设置为0,如下所示:

tinyint default 1

这是我的主题和回复部分的代码。...据我所知,如果我将tinyint的默认值设置为1,则不必在我的插入语句中正确包含它吗?

<? php
include_once 'header2.php';
if (!$_SESSION['u_uid']) {
  header("Location: index.php?create_music_topic_process=notlogin");
  exit();
} else {

  include_once 'includes/dbh.php';
  $topic_id = $_POST['topic_id'];
  $cat = $_POST['cat'];
  $admin = $_POST['admin'];
  $topic_title = $_POST['topic_title'];
  $topic_description = $_POST['topic_description'];
  $date = date("Y-m-d H:i:s");

  if (strlen($topic_title) < 1 || strlen($topic_title) > 64) {
    echo "<meta http-equiv='refresh' content='0;url=display_music_forum_topics.php?cat=".$cat.
    "&topic_id=".$topic_id.
    "&create_music_topic_process=wronglength'>";
    exit();
  } else {
    $sql = "INSERT INTO music_forum_topics (cat_id, topic_id, user_uid, topic_title, topic_description, date_created) VALUES (?,?,?,?,?,?);";

    $stmt = mysqli_stmt_init($conn);

    if (!mysqli_stmt_prepare($stmt, $sql)) {
      echo "SQL error";
    } else {
      mysqli_stmt_bind_param($stmt, "iissss", $cat, $topic_id, $_SESSION['u_uid'], $topic_title, $topic_description, $date);
      mysqli_stmt_execute($stmt);
    }

    $sql2 = "SELECT * FROM music_forum_topics WHERE cat_id = ? AND topic_id = ?;";

    $stmt = mysqli_stmt_init($conn);

    if (!mysqli_stmt_prepare($stmt, $sql2)) {
      echo "SQL error";
    } else {
      mysqli_stmt_bind_param($stmt, "ii", $cat, $topic_id);
      mysqli_stmt_execute($stmt);
      $result2 = mysqli_stmt_get_result($stmt);
      $resultCheck2 = mysqli_num_rows($result2);
      $row2 = mysqli_fetch_assoc($result2);
      $id = $row2['id'];
    }

    echo "<meta http-equiv='refresh' content='0;url=display_music_forum.php?create_music_topic=success'>";

  }


}

这是我的回复代码:

<? php
include_once 'header2.php';
if (!$_SESSION['u_uid']) {
  header("Location: index.php?create_music_topics_process=notlogin");
  exit();
} else {
  if (!isset($_POST['submit'])) {
    header("Location: create_music_topics_reply.php?create_music_topics_process=error");
    exit();
  } else {
    $reply = $_POST['reply'];
    $cat = $_POST['cat'];
    $topic_id = $_POST['topic_id'];
    $topic_title = $_POST['topic_title'];
    $date = date("Y-m-d H:i:s");
    $creator = $_POST['creator'];
    $admin = $_POST['admin'];
    $topic_reply = $row2['topic_reply'];
    $topic_reply += 1;
    $unique_id = $_POST['unique_id'];
    $original_thread = 0;

    $sql = "INSERT INTO music_forum_topics (cat_id, topic_id, original_thread, user_uid, topic_title, topic_description, date_reply) VALUES (?,?,?,?,?,?,?);";

    if (!mysqli_stmt_prepare($stmt, $sql)) {
      echo "SQL error";
    } else {
      mysqli_stmt_bind_param($stmt, "iiissss", $cat, $topic_id, $original_thread, $creator, $topic_title, $reply, $date);
      mysqli_stmt_execute($stmt);


    }

    $sql2 = "SELECT * FROM music_forum_topics WHERE topic_id = ? AND cat_id = ?;";

    $original_thread = 0;

    if (!mysqli_stmt_prepare($stmt, $sql2)) {
      echo "SQL error";
    } else {
      mysqli_stmt_bind_param($stmt, "ii", $topic_id, $cat);
      mysqli_stmt_execute($stmt);
      $result2 = mysqli_stmt_get_result($stmt);
      $resultCheck2 = mysqli_num_rows($result2);

      $sql3 = "UPDATE music_forum_topics
      SET topic_reply = ?
        WHERE original_thread = ?
        ";

      if (!mysqli_stmt_prepare($stmt, $sql3)) {
        echo "SQL error";
      } else {
        mysqli_stmt_bind_param($stmt, "ii", $resultCheck2, $original_thread);
        mysqli_stmt_execute($stmt);

        echo "<meta http-equiv='refresh' content='0;url=display_music_forum.php?create_music_topics_reply_process=success'>";
      }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

首先,您可以尝试从用于访问数据库的任一工具中手动将值插入db。

如果该工作正常,则意味着您的代码有错误,否则该错误仅存在于您的数据库中。