drddx3115 2013-07-30 06:32
浏览 40
已采纳

未插入自动增量ID

I am using simple MySQL code to insert data from a form with auto_increment id, it works fine on local host but not on server.

this is the code I am using

 $myvar=$_POST['var'];
 //Insert data into mysql table
$sql="INSERT INTO mytable(id,myvar) VALUES ('','$myvar')";

in local host phpmyadmin data is inserted in table but on server phpmyadmin data is not inserted in table. In my localhost I am using XAMPP whereas phpmyadmin on IIS server. What setting should I do in phpmyadmin on server so that id is automatically inserted with auto increment, I know I can use mysql_insert_id() to insert id but in lots of file i have used this type of code which I cannot change. I want the same setting as XAMPP that can take this type of code easily.

  • 写回答

5条回答 默认 最新

  • dpw50696 2013-07-30 06:35
    关注

    auto increment inserts id itself so you don't need to pass it through code

    $sql="INSERT INTO mytable(myvar) VALUES ('$myvar')";
    

    or you can do this

    $sql="INSERT INTO mytable(id,myvar) VALUES (NULL,'$myvar')";
    

    if you want want to manually insert id for some reason

    $sql="INSERT INTO mytable(id,myvar) VALUES (10,'$myvar')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件