我已经提出了以下内容,但是发布到SQL有问题,是否可以帮助/解释如何使其工作?
我走了表格的路线 - 在会话中存储详细信息 - 点击确认 - 在数据库中发送电子邮件/存储 - 销毁会话。
除了存储到SQL数据库之外,一切都有效。
这是我发给SQL代码的帖子。
<?php include 'config.php'; ?>
<?php
//database connection
$db = new mysqli("$dbhost", "$dbuser", "$dbpass");
$db->select_db("$dbname");
?>
<?php
if (isset($_POST['register'])) {
//geting the values from user input form index
$fname = $_SESSION['fname'];
$lname = $_SESSION['lname'];
$address1 = $_SESSION['address1'];
$address2 = $_SESSION['address2'];
$city = $_SESSION['city'];
$postcode = $_SESSION['postcode'];
$email = $_SESSION['email'];
$phone = $_SESSION['phone'];
$charity = $_SESSION['charity'];
$est_donation = $_SESSION['est_donation'];
//query
if ($db->query("INSERT INTO registrant
(fname,lname,address1,address2,city,postcode,email,phone,charity,est_donation)
VALUES ('$fname','$lname','$address1','$address2','$city','$postcode','$email','$phone','$charity','$est_donation')"))
;
}
?>
的index.php
<?php
session_start();
//Do we know the customers details?
$fname = $_SESSION['fname'];
$lname = $_SESSION['lname'];
$address1 = $_SESSION['address1'];
$address2 = $_SESSION['address2'];
$city = $_SESSION['city'];
$postcode = $_SESSION['postcode'];
$email = $_SESSION['email'];
$phone = $_SESSION['phone'];
$charity = $_SESSION['charity'];
$est_donation = $_SESSION['est_donation'];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="remember_customer.php" method="post" name="register" id="register">
First Name: <input type="text" name="fname" id="fname" value="<?php print $fname; ?>"><br>
Last Name: <input type="text" name="lname" id="lname" value="<?php print $lname; ?>"><br>
Address: <input type="text" name="address1" id="address1" value="<?php print $address1; ?>"><br>
Address: <input type="text" name="address2" id="address2" value="<?php print $address2; ?>"><br>
City: <input type="text" name="city" id="city" value="<?php print $city; ?>"><br>
Postcode: <input type="text" name="postcode" id="postcode" value="<?php print $postcode; ?>"><br>
E-mail: <input type="email" name="email" id="email" value="<?php print $email; ?>"><br>
Phone: <input type="phone" name="phone" id="phone" value="<?php print $phone; ?>"><br>
Charity: <input type="charity" name="charity" id="charity" value="<?php print $charity; ?>"><br>
Est.Donation: <input type="est_donation" name="est_donation" id="est_donation" value="<?php print $est_donation; ?>"><br>
<button type="submit" form="register" name="register" id="register">Final - Check</button>
</form>
</body>
</html>
order_confirm.php
<?php
//Start the session
session_start();
//Do we know the customers details?
$fname = $_SESSION['fname'];
$lname = $_SESSION['lname'];
$address1 = $_SESSION['address1'];
$address2 = $_SESSION['address2'];
$city = $_SESSION['city'];
$postcode = $_SESSION['postcode'];
$email = $_SESSION['email'];
$phone = $_SESSION['phone'];
$charity = $_SESSION['charity'];
$est_donation = $_SESSION['est_donation'];
if ($fname == '') {
header('location:index.php');
exit();
}
?>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#">
<head>
<title>Registration Form</title>
<meta charset="utf-8">
</head>
<body>
<h1>Register Order</h1>
<br><br>
First Name: <?php print $fname; ?><br>
last Name: <?php print $lname; ?><br>
Address: <?php print $address1; ?><br>
Address: <?php print $address2; ?><br>
City: <?php print $city; ?><br>
Post Code: <?php print $postcode; ?>
Email: <?php print $email; ?><br>
Phone: <?php print $phone; ?><br>
Charity: <?php print $charity; ?><br>
Est. Donation: <?php print $est_donation; ?><br>
<br><br>
<a href="email_action.php"><button>Confirm Order</button></a>
</body>
</html>
email_action.php
<?php
session_start();
date_default_timezone_set('Europe/London');
$sTime = date("dmYHi");
if (isset($_SESSION['fname'])) {
$fname = $_SESSION['fname'];
}
if (isset($_SESSION['lname'])) {
$lname = $_SESSION['lname'];
}
if (isset($_SESSION['address1'])) {
$address1 = $_SESSION['address1'];
}
if (isset($_SESSION['address2'])) {
$address2 = $_SESSION['address2'];
}
if (isset($_SESSION['city'])) {
$city = $_SESSION['city'];
}
if (isset($_SESSION['postcode'])) {
$postcode = $_SESSION['postcode'];
}
if (isset($_SESSION['email'])) {
$email = $_SESSION['email'];
}
if (isset($_SESSION['phone'])) {
$phone = $_SESSION['phone'];
}
if (isset($_SESSION['charity'])) {
$charity = $_SESSION['charity'];
}
if (isset($_SESSION['est_donation'])) {
$est_donation = $_SESSION['est_donation'];
}
require 'PHPMailerAutoload.php';
require 'class.phpmailer.php';
$mail = new PHPMailer;
$mail->setFrom('noreply@host.co.uk', 'Registerering Name');
$mail->addAddress($email, $fname);
$mail->AddBCC('info@host.co.uk', ' Registration');
$mail->Subject = 'Registration - Ref# ' . $ref . ' ';
$mail->isHTML(true);
$mail->Body = '<center><h1>Registration Confirmation</h1>
Thanks for registering, please find comfirmation detials below and payment instructions below.
<br><br>
If you need to amend your details please contact us at: email@host.co.uk.</p>
<h3><u>Registration Details</u></h3>
<b><span style="color:#ea00ff">Reference#</span></b>' . $ref . ' <br>
<table width="360">
<tr>
<td width=200">
' . $fname . '
' . $lname . '
<br>
' . $address1 . '<br>
' . $address2 . '<br>
' . $city . '<br>
' . $postcode . '
<br>
' . $email . '<br>
' . $phone . '<br>
' . $charity . '<br>
' . $est_donation . '<br>
</td>
<td width="160"><img src="#" width="160" height="115" alt="logo"/></td>
</tr>
</table>
';
$mail->AltBody = "Hello, my friend! This message uses plain text !";
if (!$mail->send()) {
echo 'Uh-oh.. something bad happened! Check your register form, If it is empty email as at info@host.co.uk to see if we have received it..';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Thanks for your order! You will receive a confirmation email shortly with everything you need to know, see you soon!';
}
session_destroy();
?>