dsvtnz6350 2015-01-21 10:07
浏览 81
已采纳

在xampp服务器上运行的mysql中的数据表中插入/更新

            $db= mysqli_connect('localhost',$user, $pass, $dbname);

            if (!$db) {
                die("Connection failed: " . mysqli_connect_error());
            }
            $sql="Insert into 'testtable' ('Tool','Request Date') values('selenium','2015-6-6') ";

the above code is for inserting a row in sql table running on xampp.

table has 3 fields id(primary key/auto inc.),date and tool.

for some reason the the code is not working.

I am getting no particular error .

$result = mysqli_query($db,$sql);

                print_r($result);

                if ($result) {
                       echo "success";
                } else {
                       echo "failed";
                }

only "failed" in printed in console,web browser etc.

  • 写回答

2条回答 默认 最新

  • dongxiaoguang9108 2015-01-21 10:11
    关注

    You can't use single quotes to specify field or table names, you must use backticks. The correct MySQL query would be:

    Insert into `testtable` (`Tool`,`Request Date`) values('selenium','2015-6-6')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd
  • ¥50 C# 使用DEVMOD设置打印机首选项
  • ¥15 麒麟V10 arm安装gdal
  • ¥20 OPENVPN连接问题
  • ¥15 flask实现搜索框访问数据库
  • ¥15 mrk3399刷完安卓11后投屏调试只能显示一个设备
  • ¥100 如何用js写一个游戏云存档