I have a simple script which I have included here. the select query works fine but the insert query fails. I am running php, apache and mysql on my macbook.

我有一个简单的脚本,我在这里包含。 select查询工作正常但插入查询失败。我在我的macbook上运行php,apache和mysql。

The table city_profile has ID as a auto increment primary key. And name is a non-null.

表city_profile具有ID作为自动增量主键。并且名称是非空的。

function testMySQL()    {
  $db = new mysqli('localhost', 'root', NULL, 'citee');
  //$query = "select * from city_profile"; //this query works
  $query = "insert into city_profile ('name','state','country') values ('charlotte','north  carolina','usa')"; 
  //whereas the above one fails..
  $results = $db->query($query); 
  if($results)  {
    echo '<p>The query is successful.</p>';
  }else {
    echo '<p>The query is NOT successful.</p>';
  } 

  //close the connection
 $db->close();
}

1 个解决方案

#1


3

try to change this line:

尝试更改此行:

$query = "insert into city_profile ('name','state','country') values ('charlotte','north  carolina','usa')"; 

into this:

$query = "insert into `city_profile` (`name`,`state`,`country`) values ('charlotte','north  carolina','usa')"; 

更多相关文章

  1. shell脚本中mysqldump的基本使用
  2. 使用Powershell对MySQL运行SQL脚本
  3. 如何知道php脚本中的名称是指mysql表还是mysql视图
  4. 是一个mysql临时表,每个用户访问创建它的脚本是唯一的...?
  5. mysql启动脚本——指定数据目录并指定配置文件
  6. Spring Security ACL使用MySQL配置与数据库脚本
  7. MySql查询脚本,每月统计活动用户。
  8. MySQL导出和导入SQL脚本
  9. MySQL在Linux下Shell脚本操作命令

随机推荐

  1. java生成XML的方法
  2. php操作xml入门之xml标签的属性分析
  3. Java生成和解析XML格式文件和字符串的实
  4. php 修改、增加xml结点属性的实现代码
  5. php操作xml
  6. Java如何读取XML文件 具体实现
  7. Java中构造、生成XML简明教程
  8. XML和YAML的使用方法
  9. 在java中使用dom4j解析xml(示例代码)
  10. PlayFramework完整实现一个APP(十四)