dongwenyou4298 2014-10-03 17:41
浏览 37
已采纳

INSERT INTO语句不会将数据发布到表[关闭]

I am trying to post data to a table in my database, but there is no error messages as to why the data is not posted. I have inserted data into the table in phpmyadmin and this data is printed with the result while loop, but data will not post to the table.

<!-- form to take input-->
    <form name='form1' method='post'>
    Name:
    <input type='text' name='Name' id='name' /> <br />
    Comment:
    <input type='text' name='Comment' id='comment' /> <br />
    <input type="submit" name='submit' value="Submit" id='submit'>
    </form>
    <!-- start php-->
    <?php
            if(isset($_POST['submit']))
            {
                $name = $_POST['Name'];
                $comment = $_POST['Comment'];
            }

            $con = mysqli_connect("localhost", "kodie", "hill1124", "comments");
            if(mysqli_connect_errno())
            {
                echo "Failed to connect to MySql: ". mysqli_connect_error();
            }

            mysqli_query($con, "INSERT INTO commenttable VALUES ('$name','$comment',NOW()");
            $query = "SELECT * FROM commenttable"; 
            $result = mysqli_query($con, $query);
            $hash = $result;
            echo "<table>";
            if($hash = NULL)
            {
                echo "null";
            }
            while($row = mysqli_fetch_array($result))
            {   
            echo "<tr><td>" . $row['Name'] . "</td><td>" .  $row['comment'] . "</td><td>" . $row['timestamp'] . "</td></tr>";  //$row['index'] the index here is a field name
            }

            echo "</table>"; 

            mysqli_close($con); 

    ?>

I am unsure why it won't post, I don't think it is permissions but I am new to using mysql and don't understand why the statement compiles without errors but doesn't actually put the data on the table.

Any help is appreciated.

  • 写回答

5条回答 默认 最新

  • dongsu7049 2014-10-03 17:48
    关注

    You are missing a closing ) at the end of your insert statement:

    mysqli_query
       ($con, 
        "INSERT INTO commenttable VALUES ('$name','$comment',NOW())");
        //                                               This one ^
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入