【发布时间】:2014-02-18 11:15:25
【问题描述】:
这将是我的一段代码。
$name = $_POST['UserNames'];
$pw = sha1($_POST['Passwords']);
$mail = $_POST['Emails'];
$pc = $_POST['Postcodes'];
$status = "0";
mysql_query("INSERT INTO userinfo
(Username,Password,Email,Postcode,status,valid)
VALUES
('$name','$pw','$mail','$pc','$status','$validate')
");
我如何确保每个输入都不会为空,并且电子邮件永远不会重复。
【问题讨论】:
-
array_filter for
$_POSTand array_unique for$_POST['Emails'](如果是数组) -
在数据库中的列上设置
UNIQUE索引,并编写代码在插入之前验证输入。