php - sign up form with auto generated password and user hash_key for email confirmation -
hi friends trying create sign form generate auto password users , hash key needed email verification before 1 can log in account having problem, values cannot entered database. please help. here code.
if(isset($_get['usertype'])){ $user=$_get['usertype']; if($user==1){ $acc="starter account"; } else if($user==2){ $acc="basic account"; } else{ $acc="premium account"; } $hash_key=md5(rand(0,1000)); $pass=md5(rand(1000,5000)); if(isset($_post['add'])){ $first_name=mysqli_real_escape_string($con, $_post['first_name']); $surname=mysqli_real_escape_string($con, $_post['surname']); $username=mysqli_real_escape_string($con, $_post['username']); $email=mysqli_real_escape_string($con, $_post['email']); $timestamp=strtotime("+21 days"); $o_date=date('y-m-d h:i:s', $timestamp); $j_date=date('y-m-d h:i:s'); if (( !preg_match ("/^[a-za-z\s]+$/",$first_name))||(strlen($first_name) < 3)) { $first_name_error= "<p class='text-danger'>your first name should contain letters , must not less 3 characters</p>"; } if (( !preg_match ("/^[a-za-z\s]+$/",$surname))||(strlen($surname) < 3)) { $surname_error= "<p class='text-danger'>your surname should contain letters , must not less 3 characters</p>"; } if (( !preg_match ("/^[a-za-z\s]+$/",$username))||(strlen($username) < 3)) { $username_error= "<p class='text-danger'>your username should contain letters , must not less 3 characters</p>"; } if(!filter_var($email,filter_validate_email)){ $email_error= "<p class='text-danger'>please use valid email</p>"; } if(mysqli_num_rows(mysqli_query($con,"select * users username='$username'"))>0){ $username_rep_error="that username taken"; } if(mysqli_num_rows(mysqli_query($con,"select * users email='$email'"))>0){ $email_rep_error="that email taken"; } if((empty($first_name_error))&&(empty($surname_error))&&(empty($username_error))&&(empty($username_rep_error))&&(empty($email_rep_error))&&(empty($email_error))){ if(mysqli_query($con,"insert users (first_name,surname,username,email,password,account,join_date,offer_expirely,hash_key) values('$first_name','$surname','$username','$email','$pass','$acc','$j_date','$o_date','$hash_key')")){ $to = $email; // send email our user
$subject = 'signup | verification'; // give email subject $message = '
thanks signing up! account has been created, can login following credentials after have activated account pressing url below.
username: '.$username.'
password: '.$password.'
please click link activate account: http://www.mysite.co.ke/verify.php?email='.$email.'&hash='.$hash.'
'; // our message above including link
$headers = 'from:noreply@mysite.co.ke' . "\r\n"; // set headers mail($to, $subject, $message, $headers); // send our email $valid_msg="your account has been made,
please verify clicking activation link has been sent email.
} }
remove single quotes
try this
if(mysqli_query($con,"insert users (first_name,surname,username,email,password,account,join_date,offer_expirely,hash_key) values($first_name,$surname,$username,$email,$pass,$acc,$j_date,$o_date,$hash_key)")){
Comments
Post a Comment