我非常 PHP新手-我正试图通过实践学习来教自己一点web编程。我偶然发现了这个:https://www.youtube.com/watch?v=CS45YAqCgX8关于如何建立评论区的视频系列,但是我卡住了。
我的第一个PHP文件看起来是这样的:
<?php
require('connect.php');
If(isset($_POST['submit']))
{
$name=$_POST['name'];
$comment=$_POST['comment'];
If(name&&comment)
{
$insert=mysqli_query("INSERT INTO comment (name,comment) VALUES ('$name','$comment')");
}
}
/*else
echo "Please fill out your name and leave a comment.*/
?>
<html>
<br/>
<br/>
<body>
<form action = "CommentForm.php" method = "post">
<table>
<br/>
<tr><td>Name: </td><td><input type = "text" name = "name" size = "30"/></td></tr>
<tr><td colspan="2">Comment:</td></tr>
<tr><td colspan="2"><textarea name = "comment"></textarea></td></tr>
<tr><td colspan="2"><input type = "submit" name = "submit" value = "Comment"/></td></tr>
</table>
</form>
</body>
</html>
连接文件为:
<?php
mysqli_connect("My Host", "My Username","My Password");
mysqli_select_db("My Database");
?>
和我想要附加它的HTML是这样的
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title>Pokemon</title>
<link rel = "stylesheet" type = "text/css"
href = "stylishandviewtiful.css">
</head>
<body>
<br/>
<br/>
<br/>
<br/>
<h3><a href = "Competitive Meta and Community.html">Competitive Meta and Community</a></h3>
<h3><a href = "Game StorylinesTheoriesOverthought.html">In-Game Story Ideas and Opinions</a></h3>
</body>
<?php include 'CommentForm.php'; ?>
</html>
我想我不能只是使用一个包含函数?如果将第一个PHP应用程序中的HTML分离到它自己的文件中,会有更好的结果吗?
对于这个特定的实例,我可能通常需要一个教程,它开始的速度足够慢,任何外行人都可以跟随。
您忘记将连接放入mysqli_query($con,"insert…")中否则,插入将被链接到$link。$con=mysqli_connect("localhost","my_user","my_password","my_db");将$con传递给mysqli_query
见http://www.w3schools.com/php/func_mysqli_query.asp
,如果您的表单仍然没有出现,您需要查看您的包含文件。如果有错误,它将中止