dongyan2267 2015-10-01 08:45
浏览 50

使用HTML表单和MySQL数据库在PHP中的注释部分

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.

  • 写回答

1条回答 默认 最新

  • douyue1926 2015-10-01 10:01
    关注

    You forgot to put the connection inside the mysqli_query($con,"insert ...") otherwise your insert will be linked to $link. second try making connection like this $con=mysqli_connect("localhost","my_user","my_password","my_db"); pass your $con to your mysqli_query

    see http://www.w3schools.com/php/func_mysqli_query.asp

    and if your form still does not appear you need to look at your include file. If there is something wrong it will abort

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题