【发布时间】:2017-10-07 06:06:45
【问题描述】:
我对使用 PHP 非常陌生。我想为用户创建一个评论框。
1.如何将评论保存在数据库中
2.怎么看有没有帖子
3. 如何将所有帖子显示到当前页面。
我正在使用 Wampsever/MySQL 工作台。我可以帮忙吗?谢谢!
<?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 开发并想要制作应用程序,请选择适合您的风格和需求的 development framework,例如 Laravel。这些带有许多示例,说明如何完全按照您的要求进行操作。您创建的是一堆令人困惑的 HTML、CSS、PHP 和 SQL,没有关注点分离,这是尝试学习 PHP 时的常见错误。框架可帮助您专注于手头的任务,并使您和其他人都能维护您的代码。
-
@Alton Joyner 据我了解您的问题,您希望在图像或视频下方添加一个评论框。就像现在的电影网站一样。我说得对吗
-
@PavanBaddi 是正确的
-
@Alton Joyne 然后确定在几分钟内我会发布答案
-
@PavanBaddi 谢谢
标签: php mysql sql html wampserver