Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello I am currently working with a code project ecommerce site to improve myself. The problem is that during the registration process it asks me to fill in the fields even if it's already done. Please help me and good luck to you.sorry for my bad English

What I have tried:

I tried modifying the database and then trying again but it doesn't work.
Posted
Comments
Member 8428760 10-Oct-22 19:39pm    
Are you using an auto filler to populate the fields? Sometimes it doesn't pick up the data even thought it is in the boxes.
Cedric Pare 10-Oct-22 19:59pm    
hello I have filled in manually but nothing to do. I tried redefining the recheck form but nothing. as if there was an empty field that I can't see.
Member 8428760 10-Oct-22 20:13pm    
Without being able to see the code, it is hard to know what is blocking it.
Cedric Pare 10-Oct-22 20:18pm    
?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

include 'includes/session.php';

if(isset($_POST['signup'])){
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$password = $_POST['password'];
$repassword = $_POST['repassword'];

$_SESSION['firstname'] = $firstname;
$_SESSION['lastname'] = $lastname;
$_SESSION['email'] = $email;

if(!isset($_SESSION['captcha'])){
require('recaptcha/src/autoload.php');
$recaptcha = new \ReCaptcha\ReCaptcha('6LevO1IUAAAAAFCCiOHERRXjh3VrHa5oywciMKcw', new \ReCaptcha\RequestMethod\SocketPost());
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);

if (!$resp->isSuccess()){
$_SESSION['error'] = 'Please answer recaptcha correctly';
header('location: signup.php');
exit();
}
else{
$_SESSION['captcha'] = time() + (10*60);
}

}

if($password != $repassword){
$_SESSION['error'] = 'Passwords did not match';
header('location: signup.php');
}
else{
$conn = $pdo->open();

$stmt = $conn->prepare("SELECT COUNT(*) AS numrows FROM users WHERE email=:email");
$stmt->execute(['email'=>$email]);
$row = $stmt->fetch();
if($row['numrows'] > 0){
$_SESSION['error'] = 'Email already taken';
header('location: signup.php');
}
else{
$now = date('Y-m-d');
$password = password_hash($password, PASSWORD_DEFAULT);

//generate code
$set='123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$code=substr(str_shuffle($set), 0, 12);

try{
$stmt = $conn->prepare("INSERT INTO users (email, password, firstname, lastname, activate_code, created_on) VALUES (:email, :password, :firstname, :lastname, :code, :now)");
$stmt->execute(['email'=>$email, 'password'=>$password, 'firstname'=>$firstname, 'lastname'=>$lastname, 'code'=>$code, 'now'=>$now]);
$userid = $conn->lastInsertId();

$message = "

Thank you for Registering.


Your Account:
Email: ".$email."
Password: ".$_POST['password']."
Please click the link below to activate your account.
Activate Account
";

//Load phpmailer
require 'vendor/autoload.php';

$mail = new PHPMailer(true);
try {
//Server settings
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'testsourcecodester@gmail.com';
$mail->Password = 'mysourcepass';
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;

$mail->setFrom('testsourcecodester@gmail.com');

//Recipients
$mail->addAddress($email);
$mail->addReplyTo('testsourcecodester@gmail.com');

//Content
$mail->isHTML(true);
$mail->Subject = 'ECommerce Site Sign Up';
$mail->Body = $message;

$mail->send();

unset($_SESSION['firstname']);
unset($_SESSION['lastname']);
unset($_SESSION['email']);
Member 8428760 10-Oct-22 20:23pm    
Have you verified that this is getting set properly? $_SESSION['captcha']

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900