0
다음 코드는 사용자가이 양식을 통해 이메일과 우편 번호를 제출하는 것입니다. 데이터를 확인하거나 데이터를 데이터베이스에 삽입하거나 오류 메시지를 제대로 표시하지 않습니다.이 간단한 PHP 이메일/우편 양식을 제출할 수 없습니다.
<?php
// If the form submit button is set and the email and zip fields are not empty, proceed and process
if(isset($_POST['submit']) && !empty($_POST['email']) && !empty($_POST['zip']))
{
// Create variables for form input fields
$email = $_POST['email'];
$zip = $_POST['zip'];
// Create an array to capture errors
$errors = array();
// Create variable to capture success message
$success = "Thanks for signing up!";
// Email Validation
// Check to see if user entered a valid email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$errors[] = "Invalid email address.";
}
// Check email length
if(strlen($email) < 6)
{
$errors[] = "Invalid email address.";
}
// Check email length
if(strlen($email) > 50)
{
$errors[] = "Invalid email address.";
}
// Zip Code Validation
// Check to see if zip code is a number
if((!is_numeric($zip) || strlen($zip) != 5))
{
$errors[] = "Invalid zip code.";
}
// Include database config file and establish db connection
require("includes/config.php");
mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD) or die("Database Connection Error");
mysql_select_db(DB_NAME) or die("No Database Found");
// Check to see if email already exists in database
$email_check_query = "SELECT email FROM datingshotgun WHERE email ='$email'";
$run_email_check_query = mysql_query($email_check_query);
// If MySQL query returns any results, user has already signed up and the script will end
if(mysql_num_rows($run_email_check_query) != 0)
{
$errors[] = "Looks like you already signed up...";
}
// If there are no errors above run this block of code
if(count($errors) == 0)
{
// Include database config file and establish db connection
require("includes/config.php");
mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD) or die("Database Connection Error");
mysql_select_db(DB_NAME) or die("No Database Found");
// Insert email and password into database
$insert_email_query = "INSERT INTO datingshotgun (email,zip) VALUES ('$email','$zip')";
$run_insert_email_query = mysql_query($insert_email_query);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>DatingShotgun.com</title>
<link rel="stylesheet" href="css/styles.css" />
<!-- TypeKit -->
<script type="text/javascript" src="http://use.typekit.com/mtx2hld.js"></script>
<script type="text/javascript">try {
Typekit.load();
} catch (e) {
}</script>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<!-- Custom Script -->
<script src="js/scripts.js"></script>
</head>
<body>
<header>
<div class="logo">
<h1>Dating Shotgun</h1>
</div>
</header>
<div class="content">
<div class="comingsoon"><p class="comingsoon_image"></p></div>
<h1>Sign Up Now</h1>
<p class="description">Be the first to receive a weekly dose of eligible<br />bachelors handpicked by two girls on
the prowl.</p>
<form action="index.php" method="post">
<input type="email" class="email" name="email" maxlength="50" placeholder="Email Address">
<input type="text" class="zip" name="zip" maxlength="5" placeholder="Zip Code">
<input type="submit" class="submit" name="submit" value="Submit">
<p class="errors">
<?php
if(count($errors) != 0)
{
foreach($errors as $error)
{
echo $error . "<br />";
}
}
else
{
echo $success;
}
?>
</p>
</form>
</div>
<footer>
<p class="line"></p>
<a href="http://flirtexting.com/" title="Flirtexting"></a>
</footer>
</body>
</html>
스크립트를 복사하여 붙여 넣으려고했는데 데이터베이스 부분을 주석 처리했습니다. 모든 오류 메시지가 완벽하게 나옵니다. 출력을 전혀 얻지 못합니까? 아니면 당신이 보는 것과 같은 페이지일까요? 우리는 좀 더 도움이 필요합니다. – Repox
출력이 전혀 없으며 페이지가 새로 고침 만합니다. –
config.php 파일이 올바른지 확인합니다. –