dqpfkzu360216 2014-03-19 02:57
浏览 207

Mysql将id插入为0

I am trying to make a revisions page, but when I insert a new revision, it sets the id to 0 instead of 1 more than the last entry, so I can make 1 new revision, but no more. Here is my mySQL code:

("INSERT INTO `revisions` (version, author, content, `date`) VALUES ('".$version."', '".$_SESSION['username']."', '".$content."', '".$date."')");

Edit: Wow that was embarrassing... I made the table id default 0... Schema:

CREATE TABLE `revisions` (
 `id` int(11) NOT NULL,
 `version` varchar(255) NOT NULL,
 `author` varchar(255) NOT NULL,
 `content` varchar(255) NOT NULL,
 `status` int(255) NOT NULL,
 `date` varchar(255) NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
  • 写回答

3条回答 默认 最新

  • dongyingjiu0669 2014-03-19 03:02
    关注

    :) it saids clearly

    id int(11) NOT NULL DEFAULT '0'

    it will be inserted as default value 0 if you dont make any value , then it will be 0 as default.

    if you wanna be 1 as default then use this

    id int(11) NOT NULL DEFAULT '1'

    or if you want it be incremented then use this

    id int(11) NOT NULL AUTO_INCREMENT

    //this will be automatically 1,2,3,4,...values incremented everytime you inseret new value

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)