儘管項目已成功添加到數據庫,但我不確定是否正確執行了mysql_real_escape_string()函數,從而導致了錯誤。任何幫助表示讚賞。mysqil_real_escape_string()錯誤我無法修復
成功!
警告:array_map()[function.array映射]:參數#2應在/home/site4/public_html/lab/mailing_list_dev_1-0/mailing_list_add.php陣列上線32個
感謝報名!
這裏是有問題的代碼...
<?php
// connects the database access information this file
include("mailing_list_include.php");
// the following code relates to mailing list signups only
if (($_POST) && ($_POST["action"] == "sub")) {
if ($_POST["email"] == "") {
header("Location: mailing_list_add.php");
exit;
} else {
// connect to database
doDB();
// filtering out anything that isn't an email address
if (filter_var(($_POST["email"]), FILTER_VALIDATE_EMAIL) == TRUE) {
echo 'Success!';
} else {
echo 'Invalid Email Address';
exit;
}
// check that the email is in the database
emailChecker($_POST["email"]);
// get number of results and do action
if (mysqli_num_rows($check_res) < 1) {
// free result
mysqli_free_result($check_res);
// cleans all input variables at once
$email = array_map("mysqli_real_escape_string", ($_POST["email"]));
// add record
$add_sql = "INSERT INTO subscribers (email)
VALUES('".$_POST["email"]."')";
$add_res = mysqli_query($mysqli, $add_sql)
or die(mysqli_error($mysqli));
$display_block = "<p>Thanks for signing up!</p>";
// close connection to mysql
mysqli_close($mysqli);
} else {
// print failure message
$display_block = "You're email address, ".$_POST["email"].", is already subscribed.";
}
}
}
?>
<html>
<?php echo "$display_block";?>
</html>
試過線$電子郵件= mysqli_real_escape_string($ _ POST [「電子郵件」]); ,並得到這個錯誤:「警告:mysqli_real_escape_string()期待恰好2參數,1在/home/site4/public_html/lab/mailing_list_dev_1-0/mailing_list_add.php在32行」 – Andy 2012-02-22 17:24:41
@安迪抱歉,我沒有注意到你正在使用'mysqli'而不是舊的'mysql'函數。您必須傳遞連接到數據庫時創建的鏈接資源。我把'$ dbConn'放進''doDB()'函數內部。 – 2012-02-22 17:27:47
哇,真棒幫助,謝謝。我也有一個類似的腳本來刪除地址,我是否也需要應用相同的過濾器?或者刪除一些不添加任何東西到MySQL所以不能造成任何損害?此外,這足以防止惡意代碼在你看來? – Andy 2012-02-22 17:37:21