Tôi đã nhận được 4 lỗi trong khi chạy mã này thêm địa chỉ email của người dùng vào cơ sở dữ liệu có tên ecommerce
trong bảng có tên là subscriptions
.
$ con = new mysqli ['localhost', 'root', '', 'thương mại điện tử'];
if [!$con] {
die['Could not connect: ' . mysql_error[]];
}
$errors = array[];
if[$_POST]
{
if[empty[$_POST['email']]]
{
$errors['email1'] = "Dont forget to write your email!
";
}else {
$email = test_input[$_POST["email"]];
// check if e-mail address is well-formed
if [!filter_var[$email, FILTER_VALIDATE_EMAIL]] {
$errors['email2'] = "Something wrong is with your email
";
}else{
// check if the email already exists
$query = mysqli_query["SELECT * FROM subscriptions WHERE email='$email'"];
if[mysqli_num_rows[$query] > 0]{
$errors['email3'] = "Your had been registered before!
";
}
}
}
//check errors
if[count[$errors] == 0]
{
$insert_email = mysqli_query["INSERT INTO subscriptions [email] VALUES ['$email']"];
$insert_email = mysqli_query[$con, $insert_email];
$success = "alert['Your email was successfully added to our database!']";
}
}
function test_input[$data] {
$data = trim[$data];
$data = stripslashes[$data];
$data = htmlspecialchars[$data];
return $data;
}
?>