2

基本的に、ユーザーがサインアップできる登録フォームがあり、登録ごとに一意の確認コードがデータベースに生成され、サインアップ時にユーザーに電子メールで送信されます。

私は現在、ユーザーが電子メールのリンクをクリックしてverification.phpに移動する第2段階に取り組んでいます

このページで、ユーザーは電子メールで送信された検証/登録コードを入力する必要があります。ここにあるスクリプトは、検証コードを探して、データベースにあるものと一致することを確認する必要があります。

私がやりたいことは、確認コード/登録コードがデータベースに保持されているものと正しい場合、その確認コードに一致するそのユーザーのために保持している電子メールアドレスに確認メールを送信することをクエリに伝えることです. (同じ確認コードを持つその行に属する電子メールです。)

私のテーブルはこんな感じ

id           email               registration_code (verification code)
1      example@email.com                    5093dkfd

現在、クエリはデータベースに保持されている登録コードを検索しますが、その登録コードに一致する電子メールを見つけて電子メールを送信する方法がわかりません。このビット私は助けが必要です。誰でも私を正しい方向に向けてください、

また、クエリで、コードを正しく入力したかどうかをユーザーに伝えたいと思っています。

/**
 * ShuttleCMS - A basic CMS coded in PHP.
 * Verification Code Check - Used to confirm a user's verification code
 * 
 */
define('IN_SCRIPT', true);
// Start a session
session_start();

//Connect to the MySQL Database
include 'includes/_config/connection.php';


/*
 * Checks form field for verification code, then where verification code has email, send email to recipient     
 */

if ($_POST['verificationcode']=='') {
        header('Location: verification.php?err=1');
}
if(get_magic_quotes_gpc()) {
        $verificationcode = htmlspecialchars(stripslashes($_POST['verificationcode']));
} 
else {
        $verificationcode = htmlspecialchars($_POST['verificationcode']);

}


/*
 * Checks if the verification code exists and look for email in that row which belongs to that verification code to send email out.
 */

$sql = "SELECT COUNT(*) FROM ptb_registrations WHERE registration_code = '$verificationcode' AND '$verificationcode' MATCHES email";
$result = mysql_query($sql)or die('Could not find member: ' . mysql_error());

if (!mysql_result($result,0,0)>0) {
    header('Location: verification.php?err=2');
}

次に、確認メールを送信します。

/*
         * Email out the infromation
         */


    (EMAIL BODY)
    YOUR code was matched and you are now registered etc.
4

2 に答える 2

1

まず、mysql_* 関数は非推奨になっていることに注意してください。また、mysqli や PDO (複数の SQL フレーバーをサポートする) など、他の mysql ライブラリのいずれかを使用する必要があります。

次に、選択した mysql ライブラリに適切なエスケープ関数を使用する必要があります。

一致する電子メールを選択するには、SELECT email FROM ...

結果を確認するには、num_rows 関数 ( mysql_num_rowsmysql ライブラリまたはnum_rowsmysqli のプロパティなど) から開始して、一致する電子メール アドレスが見つかったかどうかを確認し、一致が見つかった場合は、実際の行の内容をフェッチして電子メールを取得します。次に、PHP を使用してそのアドレスに電子メールを送信します。

于 2013-03-14T12:25:35.683 に答える
1

このようなものが動作するはずです:

$sql = "SELECT email FROM ptb_registrations WHERE registration_code = '$verificationcode'";
$result = mysql_query($sql)or die('Could not find member: ' . mysql_error());
if (mysql_num_rows($result) == 0) {
   header('Location: verification.php?err=2');
} else {
  $row = mysql_fetch_array($result);
  $email = $row['email'];
}
于 2013-03-14T12:19:08.340 に答える