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

在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.

图片转代码服务由CSDN问答提供 功能建议

  $ db = mysqli_connect('localhost',$ user,$ pass,$ dbname); 
  
 if(!$ db){
 die(“Connection failed:”。mysqli_connect_error()); 
} 
 $ sql =“插入'testtable'('工具','请求日期')值(  'selenium','2015-6-6')“; 
   
 
 

上面的代码用于在xampp上运行的sql表中插入一行。

表有3个字段id(主键/自动增强),日期和工具。

由于某种原因代码无效。

我没有遇到任何特殊错误。

  $ result = mysqli_query($ db,$ sql); 
 
 print_r($ result);  
 
 if($ result){
 echo“success”; 
} else {
 echo“failed”; 
} 
   
 
 

在控制台,网络浏览器等中打印“失败”。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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 );
                }
    
    点赞 打赏 评论

相关推荐 更多相似问题