如何使用php和mysql

时间:2016-05-13 04:58:40

标签: php mysql pdo

我正在尝试编写一个脚本,我需要从数据库中检索电子邮件并发送到该电子邮件的URL链接,它可以工作,但我希望它在正确的查询中,因为作为初学者我尝试但不确定如果查询正确,我在检索people_id时遇到问题,当发送链接时我得到令牌而不是student_id,我该如何解决这个问题

<?php

error_reporting(1);
session_start();

include 'includes/db.php';
include 'includes/tokengen.php';
include('classes/phpmailer/phpmailer.php');

if($_POST["Submit"]=="Submit"){

   $idcode=$_POST['idcode'];
   $_SESSION['idcode'] = $post['idcode'];

   $sql = "SELECT * FROM student WHERE idcode = :idcode";

   $stmt = $pdo->prepare($sql);

   $stmt->bindValue(':idcode', $idcode);

   $stmt->execute();

   $result = $stmt->fetch(PDO::FETCH_ASSOC);

   if(!empty($result)){
       $email = $result['email']; 
 //followed a online resource*Doubt
 //echo $email;
       $token = generateToken();
 //echo $token;
       $sql = "UPDATE student SET token = :token WHERE email = :email";
 //echo $email;
       $stmt = $pdo->prepare($sql);
       $stmt->execute(array(
           ':token' => $token,
           ':email' => $email
           ));

       $result1 = $stmt->fetch(PDO::FETCH_ASSOC);

       if(!empty($result)){
           $mail = new PHPMailer;
           $mail->isSMTP();
 //From email address and name
           $mail->From = "graymatter.com";
           $mail->FromName = "johndoe";
//To address and name
           $mail->addAddress("$email", "janedoe");
//echo $email;
//$mail->addAddress("recepient1@example.com"); //Recipient name is optional

//Address to which recipient will reply
           $mail->addReplyTo("", "Reply");

//CC and BCC
//$mail->addCC("cc@example.com");
//$mail->addBCC("bcc@example.com");

//Send HTML or Plain Text email
           $mail->isHTML(true);
           $mail->Subject = "You Registration Link!";
           $mail->Body = "http://www.empty.com/register/registration.php?token=$token&student_id=student_id";
           $mail->AltBody = 'Click to Register';
           if(!$mail->send()) 
           {
               echo "Mailer Error: " . $mail->ErrorInfo;
           } 
           else 
           {
               echo "Message has been sent successfully";
           }
       } 
   }

   else{
       echo 'You are not Registered';
   }
}
?>



<div class="container">
 <div class="row">
 <div class="col-md-5 col-md-offset-3 well">
 <form role="form" class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="regform">
 <fieldset>
 <legend>Login</legend>


 <div class="form-group">
 <div class="col-md-3">
 <label for="txt_email" class="control-label">CCODE:</label>
 </div>
 <div class="col-md-9">
 <div class="form-inline">
 <div class="form-group">
 <input class="form-control" type="text" name="idcode" required placeholder="STUDENT ID" value="<?= isset($_SESSION["idcode"]) ? $_SESSION["idcode"] : ""; ?>"/>
 <label for="idcode" generated="true" class="error">
 <?= isset($error_hash["idcode"]) ? $error_hash["idcode"] : "" ?>
 </label>
 </div>

 </div>
 </div>
 </div>


 <div class="form-group">
 <div class="col-md-12">
 <input type="submit" name="Submit" value="Submit" class="btn btn-primary"/>

 </div>


 </div>
 </fieldset>
 </form>
 </div>
</div>
</div>

0 个答案:

没有答案