感谢您提前回复。
解析错误:语法错误,第45行的insert.php中的意外T_ELSE
请检查我的insert.php代码是否有错误..尝试连接但没有成功..它在浏览器中进入insert.php,但它是一个空白页。
这是insert.php:
<?php
$email = $_POST['email'];
if (!empty($email)){
$host = "localhost";
$dbUsername = "root";
$dbPassword = "password";
$dbname = "newsletters_soon_db";
} else {
echo "Email Address is required";
die();
}
// Create Connection
$conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
if (mysqli_connect_error()) {
die('Connection Error('.mysqli_connect_error().')'.mysqli_connect_error());
}else{
$SELECT = "SELECT email from email_newsletters Where email = ? Limit 1";
$INSERT = "INSERT Into email_newsletters (email) values(?)";
//Prepare statement
$stmt = $conn->prepare($SELECT);
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($email);
$stmt->store_result();
$rnum = $stmt->num_row;
if ($rnum==0){
$stmt->close();
$stmt = $conn->prepare($INSERT);
$stmt->bind_param("s",$email);
$stmt->execute();
echo "New record inserted successfully";
} else {
echo "You are already registered using this email, please type an other email address to receive updates";
}
$stmt->close();
$conn->close();
}else {
echo "Please insert insert";
die();
}
?>
并且index.html是:
<!DOCTYPE html>
<html lang="en">
<head>
<title>local host</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->
<link rel="icon" type="image/png" href="images/icons/favicon.ico"/>
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/animate/animate.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="css/util.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<!--===============================================================================================-->
</head>
<body>
<!-- -->
<div class="simpleslide100">
<div class="simpleslide100-item bg-img1" style="background-image: url('images/bg01.jpg');"></div>
<div class="simpleslide100-item bg-img1" style="background-image: url('images/bg02.jpg');"></div>
<div class="simpleslide100-item bg-img1" style="background-image: url('images/bg03.jpg');"></div>
</div>
<div class="size1 overlay1">
<!-- -->
<div class="size1 flex-col-c-m p-l-15 p-r-15 p-t-50 p-b-50">
<h3 class="l1-txt1 txt-center p-b-25">
Coming Soon
</h3>
<p class="m2-txt1 txt-center p-b-48">
Our website is under construction, follow us for update now!
</p>
<div class="flex-w flex-c-m cd100 p-b-33">
<div class="flex-col-c-m size2 bor1 m-l-15 m-r-15 m-b-20">
<span class="l2-txt1 p-b-9 days">35</span>
<span class="s2-txt1">Days</span>
</div>
<div class="flex-col-c-m size2 bor1 m-l-15 m-r-15 m-b-20">
<span class="l2-txt1 p-b-9 hours">17</span>
<span class="s2-txt1">Hours</span>
</div>
<div class="flex-col-c-m size2 bor1 m-l-15 m-r-15 m-b-20">
<span class="l2-txt1 p-b-9 minutes">50</span>
<span class="s2-txt1">Minutes</span>
</div>
<div class="flex-col-c-m size2 bor1 m-l-15 m-r-15 m-b-20">
<span class="l2-txt1 p-b-9 seconds">39</span>
<span class="s2-txt1">Seconds</span>
</div>
</div>
<form action="insert.php" method="POST" class="w-full flex-w flex-c-m validate-form">
<div class="wrap-input100 validate-input where1" data-validate = "Valid email is required: ex@abc.xyz">
<input class="input100 placeholder0 s2-txt2" type="text" name="email" placeholder="Enter Email Address">
<span class="focus-input100"></span>
</div>
<button type="submit" value="Submit" class="flex-c-m size3 s2-txt3 how-btn1 trans-04 where1">
Subscribe
</button>
</form>
</div>
</div>
<!--===============================================================================================-->
<script src="vendor/jquery/jquery-3.2.1.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/bootstrap/js/popper.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/select2/select2.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/countdowntime/moment.min.js"></script>
<script src="vendor/countdowntime/moment-timezone.min.js"></script>
<script src="vendor/countdowntime/moment-timezone-with-data.min.js"></script>
<script src="vendor/countdowntime/countdowntime.js"></script>
<script>
$('.cd100').countdown100({
/*Set Endtime here*/
/*Endtime must be > current time*/
endtimeYear: 2018,
endtimeMonth: 06,
endtimeDate: 30,
endtimeHours: 23,
endtimeMinutes: 59,
endtimeSeconds: 59,
timeZone: "Asia/Bahrain"
// ex: timeZone: "America/New_York"
//go to " http://momentjs.com/timezone/ " to get timezone
});
</script>
<!--===============================================================================================-->
<script src="vendor/tilt/tilt.jquery.min.js"></script>
<script >
$('.js-tilt').tilt({
scale: 1.1
})
</script>
<!--===============================================================================================-->
<script src="js/main.js"></script>
</body>
</html>
我创建了一个名为newsletters_soon_db的数据库,并在其中创建了一个名为email_newsletters的表,其中一列称为电子邮件,其中包含Varchar,长度为40。
提前感谢您的帮助
答案 0 :(得分:0)
你的if(mysqli_connect_error()){else语句是否是...... else ... else
它必须是if ... else if ... else或者只删除最后一个else语句。
这是您应该在错误日志中看到的错误
解析错误:语法错误,第45行的insert.php中的意外T_ELSE