插入多个_POST值从php web表单发送到sql表
问题描述:
How could I essentially add multiple _POST values to my below statement.
$sql = "INSERT INTO emails (emailaddress) // starting action
VALUES ('".$_POST['email']."')"; // I would like to add more values to send here
我怎样才能在下面的语句中添加多个_POST值。 p>
$ sql =“INSERT INTO电子邮件(emailaddress)//开始行动
VALUES('”。$ _ POST ['email']。“')”; //我想添加更多值来发送到这里
code> pre>
div>
答
- You HAVE to escape your variable. Read about SQL-injections here
- You can make a foreach statement. Example:
foreach($_POST as $emailaddress){ $sql = "INSERT INTO emails (emailaddress) VALUES (" . $emailaddress . ")"; // Execute query here. }
This codesnippet is just for demonstrational purposes, so do not use it directly. Escape the emailaddress first.