What's new

Help Php gadz pasok i need ur help!

Code:
  if($row)
  {
    // HERE
     $token = md5($email).rand(10,9999);
 
     $expFormat = mktime(
     date("H"), date("i"), date("s"), date("m") ,date("d")+1, date("Y")
     );

dyan mo ilagay yung checker sa may // HERE

fetch answer in db where question == question_sent
if no row return invalid question
if may row gawin mo if db_rows != answer_sent -> return invalid answer
pwede paki code paps? dq magets hehe
 
SELECT question, ans from users where email

var1 = question
var2 = ans

ans1 = $_POST['question']
ans2 = $_POST['ans']

if ((var1 == ans1) && (var2 == ans2)) {
// Send email to change password
}
 
SELECT question, ans from users where email

var1 = question
var2 = ans

ans1 = $_POST['question']
ans2 = $_POST['ans']

if ((var1 == ans1) && (var2 == ans2)) {
// Send email to change Pásswørd
}
ganto paps?
PHP:
$result = mysqli_query($conn, "SELECT question, ans from users where email = '" .$email." ' ");

     $ques = 'question';
     $ans = 'ans';
    
     $ansq1 = $_POST['question']
     $ansan2 = $_POST['ans']
    
     if (($ques == $ansq1) && ($ans ==  $ansan2)) {
     // Send email to change Pásswørd
     }
 
SELECT question, ans from users where email

var1 = question
var2 = ans

ans1 = $_POST['question']
ans2 = $_POST['ans']

if ((var1 == ans1) && (var2 == ans2)) {
// Send email to change Pásswørd
}
1634552633384.png


okay na sana paps kaso nong nilagay ko na mali yong ans bat tumuloy parin yong pag send ng reset password link sa gmail?

PHP:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
session_start();
if(isset($_POST['password-reset-tokensqa']) && $_POST['email'])
{
  include 'db_connect.php';
    
    $email = $_POST['email'];
    $password = 'password';
 
    $result = mysqli_query($conn,"SELECT * FROM users WHERE email='" . $email . "'");
 
    $row= mysqli_fetch_array($result);
 
  if($row)
  {
     $result = mysqli_query($conn, "SELECT question, ans FROM users WHERE email = '" .$email." ' ");

     $ques = 'question';
     $ans = 'ans';
    
     $ansq1 = $_POST['question'];
     $ansan2 = $_POST['ans'];
    
     if (($ques == $ansq1) && ($ans ==  $ansan2)) {
     // Send email to change Pásswørd
     }else{
      $_SESSION['error']="Something went wrong! ";
      header( "refresh:1;url=forget-password_sq.php" );
     }
     $token = md5($email).rand(10,9999);
 
     $expFormat = mktime(
     date("H"), date("i"), date("s"), date("m") ,date("d")+1, date("Y")
     );
 
    $expDate = date("Y-m-d H:i:s",$expFormat);
 
    $update = mysqli_query($conn,"UPDATE users set  password ='" . md5($password) . "', reset_link_token='" . $token . "' ,exp_date='" . $expDate . "' WHERE email='" . $email . "'");
 
    $link = "<a href='cms/reset-password.php?key=".$email."&token=".$token."'>Click to Reset password</a>";
 
    require_once('fpwvendor/autoload.php');
 
    $mail = new PHPMailer(true);
 
    $mail->CharSet =  "utf-8";
    $mail->IsSMTP();
    // enable SMTP authentication
    $mail->SMTPAuth = true;                 
    // GMAIL username
    $mail->Username = "your email gmail account";
    // GMAIL password
    $mail->Password = "your gmail password";
    $mail->SMTPSecure = "ssl"; 
    // sets GMAIL as the SMTP server
    $mail->Host = "smtp.gmail.com";
    // set the SMTP port for the GMAIL server
    $mail->Port = "465";
    $mail->From='your email gmail account';
    $mail->FromName='Luck-buy : Courier ';
    $mail->AddAddress($email);
    $mail->Subject  =  'Reset Password';
    $mail->IsHTML(true);
    $mail->Body    = 'Click on this Link to Reset Password '.$link.'';
    if($mail->Send())
    {
      $_SESSION['email']="We've sent you a reset password in your gmail account - ".$email."" ;
      header( "refresh:1;url=forget-password_sq.php" );
    
    }
    else
    {
      echo "Mail Error - >".$mail->ErrorInfo;
    }
  }else{
    $_SESSION['error']="Invalid Email Address Please check carefully ".$email."";
    header( "refresh:1;url=forget-password_sq.php" );
  }
}
?>
 

Attachments

Code:
  if($row)
  {
    // HERE
     $token = md5($email).rand(10,9999);
 
     $expFormat = mktime(
     date("H"), date("i"), date("s"), date("m") ,date("d")+1, date("Y")
     );

dyan mo ilagay yung checker sa may // HERE

fetch answer in db where question == question_sent
if no row return invalid question
if may row gawin mo if db_rows != answer_sent -> return invalid answer
pano to paps?
 
View attachment 1673104

okay na sana paps kaso nong nilagay ko na mali yong ans bat tumuloy parin yong pag send ng reset Pásswørd link sa gmail?

PHP:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
session_start();
if(isset($_POST['Pásswørd-reset-tokensqa']) && $_POST['email'])
{
  include 'db_connect.php';
   
    $email = $_POST['email'];
    $Pásswørd = 'Pásswørd';
 
    $result = mysqli_query($conn,"SELECT * FROM users WHERE email='" . $email . "'");
 
    $row= mysqli_fetch_array($result);
 
  if($row)
  {
     $result = mysqli_query($conn, "SELECT question, ans FROM users WHERE email = '" .$email." ' ");

     $ques = 'question';
     $ans = 'ans';
   
     $ansq1 = $_POST['question'];
     $ansan2 = $_POST['ans'];
   
     if (($ques == $ansq1) && ($ans ==  $ansan2)) {
     // Send email to change Pásswørd
     }else{
      $_SESSION['error']="Something went wrong! ";
      header( "refresh:1;url=forget-password_sq.php" );
     }
     $token = md5($email).rand(10,9999);
 
     $expFormat = mktime(
     date("H"), date("i"), date("s"), date("m") ,date("d")+1, date("Y")
     );
 
    $expDate = date("Y-m-d H:i:s",$expFormat);
 
    $update = mysqli_query($conn,"UPDATE users set  Pásswørd ='" . md5($Pásswørd) . "', reset_link_token='" . $token . "' ,exp_date='" . $expDate . "' WHERE email='" . $email . "'");
 
    $link = "<a href='cms/reset-Pásswørd.php?key=".$email."&token=".$token."'>Click to Reset Pásswørd</a>";
 
    require_once('fpwvendor/autoload.php');
 
    $mail = new PHPMailer(true);
 
    $mail->CharSet =  "utf-8";
    $mail->IsSMTP();
    // enable SMTP authentication
    $mail->SMTPAuth = true;                
    // GMAIL username
    $mail->Username = "your email gmail account";
    // GMAIL Pásswørd
    $mail->Pásswørd = "your gmail Pásswørd";
    $mail->SMTPSecure = "ssl";
    // sets GMAIL as the SMTP server
    $mail->Host = "smtp.gmail.com";
    // set the SMTP port for the GMAIL server
    $mail->Port = "465";
    $mail->From='your email gmail account';
    $mail->FromName='Luck-buy : Courier ';
    $mail->AddAddress($email);
    $mail->Subject  =  'Reset Pásswørd';
    $mail->IsHTML(true);
    $mail->Body    = 'Click on this Link to Reset Pásswørd '.$link.'';
    if($mail->Send())
    {
      $_SESSION['email']="We've sent you a reset Pásswørd in your gmail account - ".$email."" ;
      header( "refresh:1;url=forget-password_sq.php" );
   
    }
    else
    {
      echo "Mail Error - >".$mail->ErrorInfo;
    }
  }else{
    $_SESSION['error']="Invalid Email Address Please check carefully ".$email."";
    header( "refresh:1;url=forget-password_sq.php" );
  }
}
?>



if($row)
{
$result = mysqli_query($conn, "SELECT question, ans FROM users WHERE email = '" .$email." ' ");

$ques = 'question';// dapat yung row ng $result
$ans = 'ans'; // pati ito

$ansq1 = $_POST['question'];
$ansan2 = $_POST['ans'];
 
PHP:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
session_start();
if(isset($_POST['Pásswørd-reset-tokensqa']) && $_POST['email'])
{
  include 'db_connect.php';
   
    $email = $_POST['email'];
    $Pásswørd = 'Pásswørd';
 
    $result = mysqli_query($conn,"SELECT * FROM users WHERE email='" . $email . "'");
 
    $row= mysqli_fetch_array($result);
 
  if($row) {
     $result = mysqli_query($conn, "SELECT question, ans FROM users WHERE email = '" .$email." ' ");

     $ques = "";
     $ans = "";
     
     while ($row = mysql_fetch_array($result)) {
        $ques = $row["question"];
        $ans = $row["ans"];
     }
   
     $ansq1 = $_POST['question'];
     $ansan2 = $_POST['ans'];
   
     if (($ques == $ansq1) && ($ans ==  $ansan2)) {
         $token = md5($email).rand(10,9999);
 
     $expFormat = mktime(
     date("H"), date("i"), date("s"), date("m") ,date("d")+1, date("Y")
     );
 
    $expDate = date("Y-m-d H:i:s",$expFormat);
 
    $update = mysqli_query($conn,"UPDATE users set  Pásswørd ='" . md5($Pásswørd) . "', reset_link_token='" . $token . "' ,exp_date='" . $expDate . "' WHERE email='" . $email . "'");
 
    $link = "<a href='cms/reset-Pásswørd.php?key=".$email."&token=".$token."'>Click to Reset Pásswørd</a>";
 
    require_once('fpwvendor/autoload.php');
 
    $mail = new PHPMailer(true);
 
    $mail->CharSet =  "utf-8";
    $mail->IsSMTP();
    // enable SMTP authentication
    $mail->SMTPAuth = true;                
    // GMAIL username
    $mail->Username = "your email gmail account";
    // GMAIL Pásswørd
    $mail->Pásswørd = "your gmail Pásswørd";
    $mail->SMTPSecure = "ssl";
    // sets GMAIL as the SMTP server
    $mail->Host = "smtp.gmail.com";
    // set the SMTP port for the GMAIL server
    $mail->Port = "465";
    $mail->From='your email gmail account';
    $mail->FromName='Luck-buy : Courier ';
    $mail->AddAddress($email);
    $mail->Subject  =  'Reset Pásswørd';
    $mail->IsHTML(true);
    $mail->Body    = 'Click on this Link to Reset Pásswørd '.$link.'';
    if($mail->Send())
    {
      $_SESSION['email']="We've sent you a reset Pásswørd in your gmail account - ".$email."" ;
      header( "refresh:1;url=forget-password_sq.php" );
   
    }
    else
    {
      echo "Mail Error - >".$mail->ErrorInfo;
    }
     }else{
      $_SESSION['error']="Something went wrong! ";
      header( "refresh:1;url=forget-password_sq.php" );
     }
  }else{
    $_SESSION['error']="Invalid Email Address Please check carefully ".$email."";
    header( "refresh:1;url=forget-password_sq.php" );
  }
}
?>

pa try ts
1634554924977.png
 

Attachments

View attachment 1673186

View attachment 1673188
View attachment 1673190
goods na paps kaso nong tama na nilagay ko ayaw na magsend ng reset Pásswørd hahahaha
matuto ka mag debug para ma solve mo ganyan problem

isa isahin mo pinaka ugat ng problema

after mo ilagay tamang ans error lumabas

ang respo ay base dito

}else{
$_SESSION['error']="Something went wrong! ";
header( "refresh:1;url=forget-password_sq.php" );
}

so isipin mo bakit dyan napunta?

meaning yung if nya hindi success

so taas nun mag echo ka para malaman mo ano ba value sa db kaya nag kakaganun

so dito yun

if (($ques == $ansq1) && ($ans == $ansan2)) {

ang gawin mo sa taas nyan mag lagay ka ng

echo "ques from db = $ques ";
echo "answer from db = $ansq1";

echo "ques from user = $ans ";
echo "ques from db = $ansan2";

ngayon malalaman mo bakit ayaw mag success🙂

so base sa akin pag basa sa code ang mali mo ay
while ($row = mysqli_fetch_array($result)) {
$ques = $row["question"];
$ans = $row["ans"];
}
if (($ques == $ansq1) && ($ans == $ansan2)) {

dapat


while{ blablabla
if($row["question"] == $question_from_user) {
$right_question = $row["question"];
$right_answer = $row["ans"];
}
}

if($right_answer == $answer_from_user)

try it:)


btw wag ka gagamit ng $ans1 $ans2 ang sakit kasi sa utak nakakalito

ayusin mo pag pangalan😄
 

Similar threads

Back
Top