-1

これは、ユーザー名がデータベース内の電子メールと一致するかどうかを確認するために設計したコードです。そうでない場合は、ユーザー名を確認してください。存在しない場合は、電子メールを確認してください。存在しない場合は、新しいユーザー名を作成します。

問題は、クエリが実行され、毎回新しいユーザーが挿入されることです!! 私は何を間違っていますか??

$word = $_POST['word'];
$explination = $_POST['explination'];
$lhgat = $_POST['lhgat'];
$email = $_POST['email'];
$username = $_POST['username'];
$letterar = idar($_POST['word']);
$letteren = iden($_POST['word']);
if (!empty($word) && !empty($explination) && !empty($lhgat) && !empty($email) && !empty($username) && !empty($letterar) && !empty($letteren)) {
    //checking for username and email match
    $checkingforuserstmt = $conn->prepare('SELECT id FROM user WHERE username = username AND email = email');
    $checkingforuserstmt->execute(array(':username'   => $username, ':email' => $email));
    $checkingforuserrow = $checkingforuserstmt->fetch(PDO::FETCH_ASSOC);
    if($checkingforuserstmt->rowCount() < 0){
    //check for username only
    $checkingforuserstmt2 = $conn->prepare('SELECT id FROM user WHERE username = username');
    $checkingforuserstmt2->execute(array(':username'   => $username));
    $checkingforuserrow2 = $checkingforuserstmt2->fetch(PDO::FETCH_ASSOC);
    if($checkingforuserrow2->rowCount() < 0){   
                //check for email only
            $checkingforuserstmt3 = $conn->prepare('SELECT id FROM user WHERE email = email');
            $checkingforuserstmt3->execute(array(':email'   => $email));
            $checkingforuserrow3 = $checkingforuserstmt3->fetch(PDO::FETCH_ASSOC);
            if($checkingforuserrow3->rowCount() < 0){
                        $insertuser = $conn->prepare("INSERT INTO user VALUES('',:username,:email)");
                        $insertuser->execute(array(':username'   => $username,':email'   => $email)); }}}
4

1 に答える 1

2

:バインディングではなく、ステートメントでを使用する必要があります。例:select * from table where field = :fieldないfield = field

それ以外の場合は、値ではなく列を言っているだけです。

于 2013-06-17T02:14:30.427 に答える