关于mysql添加数据,该如何处理

WBOY
Release: 2016-06-13 13:44:40
Original
965 people have browsed it

关于mysql添加数据
INSERT INTO room (roomid,name,id1,id2)values('1','232','$_POST[id1]','$_POST[id2]')

$_POST[id1],$_POST[id2] 传过来的是值,不是ID,这里怎么处理下啊?

------解决方案--------------------
$_POST[id1],$_POST[id2] 传过来的是值不是id是怎么个概念。

是不是sql中的值是变量名,不是值啊。 
INSERT INTO room (roomid,name,id1,id2)values('1','232','{$_POST[id1]}','{$_POST[id2]}')

or

"INSERT INTO room (roomid,name,id1,id2)values('1','232','".$_POST[id1]."','".$_POST[id2]."')"
------解决方案--------------------
什么意思??
------解决方案--------------------
两张表的id不能在一个insert语句中同时插入,要分步进行。
id若设为auto_increment,那么不用插id,而且不能插入重复值。
若没有设为自增长:
sql = "insert into room(roomid,name,id1) values(".$_POST['roomid'].",'".$_POST['name']."',".$_POST['id1'].")";
查询时,进行多表查询就可以了。

------解决方案--------------------
$_POST[id1],$_POST[id2] 本来就他的value

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template