本文介绍了php mysql 插入 (max(id)+1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表image_tb,它有3个字段,id,images,link(id是auto auto_increment),这是我的插入代码:
I have a table image_tb, which has 3 fields, id,images,link (id is auto auto_increment), this is my insert code:
mysql_query(" insert into image_tb (images,link) select '".(max(id)+1).".jpeg','".$link."' from image_tb ");它返回:
Warning: max(): When only one parameter is given, it must be an array怎么修改?谢谢.
推荐答案在查询中做,
mysql_query(" insert into image_tb (images,link) select CONCAT(COALESCE((SELECT MAX(ID) + 1 FROM image_tb),1), '.jpeg'),'".$link."' from image_tb ");您的查询容易受到SQL Injection的影响,请阅读下面的文章以防止它
your query is vulnerable with SQL Injection, please read the article below to protect from it
- 如何防止 PHP 中的 SQL 注入?
更多推荐
php mysql 插入 (max(id)+1)
发布评论