I'm very new to PHP- and am trying to teach myself a bit of web programming with hands-on learning. I've stumbled upon this: https://www.youtube.com/watch?v=CS45YAqCgX8 video series on how to build a comment section, but am stuck.
My First PHP file looks as such:
<?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>
The connection file is:
<?php
mysqli_connect("My Host", "My Username","My Password");
mysqli_select_db("My Database");
?>
-and the HTML I want to attach it to is as such
<!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>
I'll suppose I can't just use an include function? Would I see a better return to separate the HTML in the first PHP application into its own file?
I may generally need a tutorial for this specific instance that starts slow enough for any layman to follow.