duan4369 2014-12-28 21:48
浏览 24
已采纳

PHP - MySql数据库信息不存储

I have been trying to figure this out for hours, I have created a database ( MySql/PHPMyadmin) and i am trying to get user input stored to be able to call back up, however the info is not making it/ saving it to the database, everything shows up okay except this part of code:

$registered = mysqli_affected_rows ($dbc);

        echo $registered. "Row is affected";

when run gives me a display of -1 row, I believe this to be a big part of the problem as everything else seems to work okay. I am a complete beginner so could you guys tell me how the best way of debugging this is.

$dbc = $dbc = mysqli_connect ($hostname, $username, $password, $dbname) OR die("Could not Connect");

To input the data to the db i have the following:

if ($_SERVER['REQUEST_METHOD'] == 'POST'){

        $comments = $_POST ['Comments'];

        if (!empty ($comments)){

        include ('mysqldb.php');

        mysqli_query ($dbc,"INSERT INTO 'User-Comments' (Comments) VALUES ('$comments')");

        $registered = mysqli_affected_rows ($dbc);

            echo $registered. "Row is affected";

        }else {
                echo "Nothing Submitted";
            }

        }
  • 写回答

2条回答 默认 最新

  • doujuegai8830 2014-12-28 22:04
    关注

    An excerpt from the documentation for function mysqli_stmt_affected_rows(): -1 indicates that the query has returned an error.

    You should check the value returned by mysqli_query(). If it returns FALSE then you can get details about the reason (error message) by using function mysqli_error().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 python进程启动打包问题
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题