php - 我对使用 PHP 很陌生。我想创建一个评论框

标签 php mysql sql html wampserver

我对使用 PHP 很陌生。我想为用户创建一个评论框。 1.如何将评论保存到数据库中 2.如何查看是否有帖子 3. 如何显示当前页面的所有帖子。
我正在使用 Wampsever/MySQL Workbench。我可以帮忙吗?谢谢!

<?php
    require_once("db_connection.php");
    require_once("needed_functions.php");

        if (isset($_POST['submit']))
        {
            //Take  Comment
            $comment_id = $_POST["comment"];

            if ($message == "" )
            {
                $query = "INSERT INTO comment (";
                $query .= "comment";
                $query .= ") VALUES (";
                $query .= " '{$comment}'";
                $query .= ")";

            //connect  &select 
            $mysqli = new mysqli("localhost", "user_id");

            //query 
            $result = $mysqli->query("INSERT INTO Comment () VALUES();") 

            //close
            $result->close();
            }
        }

?>

<!DOCTYPE html>
<html>
<title>JAE Movies</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins">
<style>
body,h1,h2,h3,h4,h5 {font-family: "Poppins", sans-serif}
body {font-size:16px;}
.w3-half img{margin-bottom:-6px;margin-top:16px;opacity:0.8;cursor:pointer}
.w3-half img:hover{opacity:1}
</style>

<body style= "background-image:url(Roll.jpg)">

<!-- Sidebar/menu -->
<nav class="w3-sidebar w3-black w3-collapse w3-top w3-large w3-padding" style="z-index:3;width:300px;font-weight:bold;" id="mySidebar"><br>
  <a href="javascript:void(0)" onclick="w3_close()" class="w3-button w3-hide-large w3-display-topleft" style="width:100%;font-size:22px">Close Menu</a>
  <div class="w3-container">
    <h3 class="w3-padding-64"><b>JAE<br>Movies</b></h3>
  </div>
  <div class="w3-bar-block">
  <a href="Homepage.php" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">Home</a> 
    <a href="signin.php" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">Sign In</a> 
    <a href="SignUp.php" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">Sign Up</a> 
    <a href="Information.php" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">Information</a> 
    <a href="Customer.php" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">Customer Service</a> 
    <a href="Admin.php" onclick="w3_close()" class="w3-bar-item w3-button w3-hover-white">Administrator</a> 
  </div>
</nav>

<!-- Top menu on small screens -->
<header class="w3-container w3-top w3-hide-large w3-light-blue w3-xlarge w3-padding">
  <a href="javascript:void(0)" class="w3-button w3-light-blue w3-margin-right" onclick="w3_open()">?</a>
  <span>JAE Movies</span>
</header>

<!-- Overlay effect when opening sidebar on small screens -->
<div class="w3-overlay w3-hide-large" onclick="w3_close()" style="cursor:pointer" title="close side menu" id="myOverlay"></div>


<!--Start Inserting Page Content-->
<div class="w3-main" style="margin-left:340px;margin-right:40px">

 <!-- Header -->
  <div class="w3-container" style="margin-top:80px" id="userhome">
    <h1 class="w3-jumbo w3-text-white"><b>Lion King</b></h1>
  </div>

  <!--Image-->

 <div class="w3-half">
      <img src="Images/LionKing.jpg" alt="LionKing" style="width:100%">
    </div>

    <!--Description-->

<div class="w3-half">
<p style="color:white";>Lion cub and future king Simba searches for his identity. His eagerness to please others and penchant for testing his boundaries sometimes gets him into trouble.</p></br>

    </div>

    <!--Buttons-->
 <div>
 <button type="submit"><a href= "http://www.imdb.com/title/tt0110357/videoplayer/vi3764362265?ref_=tt_ov_vi">WATCH TRAILER!</a></button>
 <button type="submit"><a href= "http://123moviesfree.com/watch/the-lion-king-1994-i.1-online-free-123movies.html">WATCH MOVIE</a></button>

    </div>

<!--Comments-->

<div>

<br>
<textarea rows="4" cols="50" name="comment" form="usrform">
Enter comment here...</textarea>

<form action=" " method="post" id="com">
  <input type ="submit" name="submit" value="submit" class="texty" >
</form>


</div>

最佳答案

在 PHP 中使用数据库连接时,请确保执行以下操作

//connect  &select 
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

//query 
$result = $mysqli->query("INSERT INTO tbl_name () VALUES();") // Add the update comment here
//close
$result->close();

永远记住:

连接 选择 询问 关闭

然后,您需要使用相同的过程但使用选择过程而不是插入过程来获取页面的所有评论。

关于php - 我对使用 PHP 很陌生。我想创建一个评论框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43861176/

相关文章:

java - h2 嵌入式数据库不嵌入/嵌入数据库的替代方案

sql - 尝试计算最小值与单元格中每个值之间的差异

php - 用php计算不同数据库的产品总价

MySQL group_concat 和计数

PHP:如何提取ajax数组响应

php - MYSQL:为查询选择了不正确的排序规则

mysql - 优化 Mysql 中的联合查询

php - 如何将动态 php 代码插入从 MYSQL 检索的文章中?

php - 使用 php 和 mysql 搜索多个关键字(X 喜欢)

javascript - 使用正则表达式验证 img url