$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') ";
Run Code Online (Sandbox Code Playgroud)
上面的代码用于在xampp上运行的sql表中插入一行.
table有3个字段id(主键/ auto inc.),日期和工具.
由于某种原因,代码不起作用.
我没有特别的错误.
$result = mysqli_query($db,$sql);
print_r($result);
if ($result) {
echo "success";
} else {
echo "failed";
}
Run Code Online (Sandbox Code Playgroud)
仅在控制台,网络浏览器等中打印出"失败".
您不能使用单引号指定字段或表名,必须使用反引号.正确的MySQL查询将是:
Insert into `testtable` (`Tool`,`Request Date`) values('selenium','2015-6-6')
Run Code Online (Sandbox Code Playgroud)