这应该会向您展示查询失败的原因,并且至少可以防止一些安全问题:
小改进
// Run by each $_POST entry and set it to empty if not found
// Clean the value against tags and blank spaces at the edges
$dataArr = array();
foreach($_POST as $key => $value) {
$dataArr[$key] = ($value == "undefined") ? '' : strip_tags(trim($value));
}
// try to perform the INSERT query or die with the returned mysql error
$query = mysql_query("
INSERT INTO members
(user, pass, mail, country, city, www, credo)
VALUES (
'".$dataArr["user"]."',
'".$dataArr["pass"]."',
'".$dataArr["mail"]."',
'".$dataArr["country"]."',
'".$dataArr["city"]."',
'".$dataArr["www"]."',
'".$dataArr["credo"]."'
)
") or die ("Error:<br/>".mysql_error());
中等改进
// Run by each $_POST entry and set it to empty if not found
// Clean the value against tags and blank spaces at the edges
$dataArr = array();
foreach($_POST as $key => $value) {
$dataArr[$key] = ($value == "undefined") ? '' : strip_tags(trim($value));
}
// escape everything
$query = sprintf("
INSERT INTO members
(user, pass, mail, country, city, www, credo)
value ('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
mysql_real_escape_string($dataArr["user"]),
mysql_real_escape_string($dataArr["pass"]),
mysql_real_escape_string($dataArr["mail"]),
mysql_real_escape_string($dataArr["country"]),
mysql_real_escape_string($dataArr["city"]),
mysql_real_escape_string($dataArr["www"]),
mysql_real_escape_string($dataArr["credo"])
);
// try to perform the INSERT query or die with the returned mysql error
$result = mysql_query($query) or die ("Error:<br/>".mysql_error());
高级改进
如果您正在开始一个新项目,或者您仍然可以改变您的方式,我强烈推荐使用PHP PDO来防止与您正在使用的当前数据库连接相关的许多安全问题。