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

在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')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • douwanc63652 2015-01-21 10:18
    关注

    try this,

    $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') ";
                $result = mysqli_query($db,$sql);
    
                print_r($result);
    
                if ($result) {
                       echo "success";
                } else {
                       echo "failed".mysqli_error( $db );
                }
    
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求局部放电案例库,用于预测局部放电类型
  • ¥100 QT Open62541
  • ¥15 stata合并季度数据和日度数据
  • ¥15 谁能提供rabbitmq,erlang,socat压缩包,记住版本要对应
  • ¥15 Vue3 中使用 `vue-router` 只能跳转到主页面?
  • ¥15 用QT,进行QGIS二次开发,如何在添加栅格图层时,将黑白的矢量图渲染成彩色
  • ¥50 监控摄像头 乐橙和家亲版 保存sd卡的文件怎么打开?视频怎么播放?
  • ¥15 Python的Py-QT扩展库开发GUI
  • ¥60 提问一下周期性信信号的问题
  • ¥15 jtag连接不上fpga怎么办