我有以下代码,它插入了一条记录,但我希望用户名和电子邮件字段是唯一的,我该如何修改我的代码来做到这一点?我也遇到了页面没有重定向到站点索引的问题。感谢任何帮助
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "createAccount")) {
$insertSQL = sprintf("INSERT INTO tblUser (username, password, userTypeKey, email) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['username'], "text"),
GetSQLValueString($_POST['user_password2'], "text"),
GetSQLValueString($_POST['userType'], "int"),
GetSQLValueString($_POST['user_email'], "text"));
mysql_select_db($database_ignite, $ignite);
$Result1 = mysql_query($insertSQL, $ignite) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}