我正在尝试建立一个注册系统,其中用户输入他的姓名和电子邮件,并接收一封电子邮件,他将在其中确认订阅。此后,此代码可用于输入一些在酒店房间办理登机手续所需的个人信息。问题是我无法将数据发送到数据库,我可以提交表单,但是数据没有发送到数据库,因此不会向该人发送电子邮件。这是代码:
<?php
//register.php
include('database_connection.php');
if(isset($_SESSION['user_id']))
{
header("location:index.php");
}
$message = '';
if(isset($_POST["register"]))
{
$query = "
SELECT * FROM tregister
WHERE email = :user_email
";
$statement = $connect->prepare($query);
$statement->execute(
array(
':user_email' => $_POST['user_email']
)
);
$no_of_row = $statement->rowCount();
if($no_of_row > 0)
{
$message = '<label class="text-danger">Email Already Exits</label>';
}
else
{
$user_activation_code = md5(rand());
$user = (isset($_POST['user_name']) && !empty($_POST['user_name'])) ? $_POST['user_name'] : "" ;
$email = (isset($_POST['user_email']) && !empty($_POST['user_email'])) ? $_POST['user_email'] : "" ;
$insert_query = "
INSERT INTO tregister
(nume, email, cod_activare, email_status)
VALUES ('$user','$email','$user_activation_code','$email_status');
";
$statement = pg_prepare($connect,$insert_query);
//HERE IT'S THE PROBLEM I think
$statement=pg_execute($connect,array(
':user_name' => $_POST['user_name'],
':user_email' => $_POST['user_email'],
':user_activation_code' => $user_activation_code,
':user_email_status' => '0'
)
);
$result = pg_fetch_all($statement);
var_dump($result);
if(isset($result))
{
$base_url = "http://dev.incorom.local/login-robinson/www/login.php"; //change this baseurl value as per your file path
$mail_body = "
<p>Hi ".$_POST['user_name'].",</p>
<p>Thanks for Registration. </p>
<p>Please Open this link to verified your email address - ".$base_url."email_verification.php?activation_code=".$user_activation_code."
<p>Best Regards,<br />Webslesson</p>
";
require 'class/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); //Sets Mailer to send message using SMTP
$mail->Host = 'smtpout.secureserver.net'; //Sets the SMTP hosts of your Email hosting, this for Godaddy
$mail->Port = '80'; //Sets the default SMTP server port
$mail->SMTPAuth = true; //Sets SMTP authentication. Utilizes the Username and Password variables
$mail->Username = ''; //Sets SMTP username
$mail->Password = ''; //Sets SMTP password
$mail->SMTPSecure = ''; //Sets connection prefix. Options are "", "ssl" or "tls"
$mail->From = 'info@webslesson.info'; //Sets the From email address for the message
$mail->FromName = 'Webslesson'; //Sets the From name of the message
$mail->AddAddress($_POST['user_email'], $_POST['user_name']); //Adds a "To" address
$mail->WordWrap = 50; //Sets word wrapping on the body of the message to a given number of characters
$mail->IsHTML(true); //Sets message type to HTML
$mail->Subject = 'Email Verification'; //Sets the Subject of the message
$mail->Body = $mail_body; //An HTML or plain text message body
if($mail->Send()) //Send an Email. Return true on success or false on error
{
$message = '<label class="text-success">Register Done, Please check your mail.</label>';
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP Register Login Script with Email Verification</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<br />
<div class="container" style="width:100%; max-width:600px">
<h2 align="center">PHP Register Login Script with Email Verification</h2>
<br />
<div class="panel panel-default">
<div class="panel-heading"><h4>Register</h4></div>
<div class="panel-body">
<form method="post" id="register_form">
<?php echo $message; ?>
<div class="form-group">
<label>User Name</label>
<input type="text" name="user_name" class="form-control" pattern="[a-zA-Z ]+" required />
</div>
<div class="form-group">
<label>User Email</label>
<input type="email" name="user_email" class="form-control" required />
</div>
<div class="form-group">
<input type="submit" name="register" id="register" value="Register" class="btn btn-info" />
</div>
</form>
<p align="right"><a href="login.php">Login</a></p>
</div>
</div>
</div>
</body>
</html>
这是database_connection:
<?php
//database_connection.php
$connect = new PDO('pgsql:host=localhost;dbname=login_robinson', 'robinson', '1234');
session_start();
?>