我的评论框没有在数据库中存储任何内容

时间:2015-02-07 10:41:13

标签: php mysql

我试图在PHP中创建一个注释框,将其值存储在数据库中。

 <?php
    include('connect.php');
    $name= isset($_POST['name']);
    $comment= isset($_POST['comment']);
    $submit=isset($_POST['submit']);
    if($submit)
    {
    if($name && $comment)
    {
    $insert= "INSERT INTO comment(name,comment) VALUES ('$name','$comment')";

    }
    else
    {
    echo "please fill out the field";
    }


    }
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Comment box</title>
    </head>

    <body>
    <form action="comment-box.php">
    <table>
    <tr><td>NAME:</td> <td><input type="text" name="name"/></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"></textarea> </td></tr> 

    </table>


    </form>
    </body>
    </html>

我的连接文件connect.php不会在我的数据库中存储任何内容。 请帮帮我。在此先感谢:)大声笑我讨厌这个redbox错误:D

    <?php

    mysql_connect('localhost','root','') or die(mysql_error());
    mysql_select_db("comment") or die ("connect select DB");  

    ?>

1 个答案:

答案 0 :(得分:3)

至少你有一个不执行的查询:

$insert= "INSERT INTO comment(name,comment) VALUES ('$name','$comment')";

你必须运行mysql_query,但是因为它已被弃用,你应该考虑 切换到mysqli_queryPDO::query

$res = mysqli_query($con, $insert, ...)

其中$con是您的连接。