Jump to content

I want to check if the User has typed it in correctly controlling on the Database.


Guitarrenchip

Recommended Posts

I want to check if the User has typed it in correctly controlling on the Database.

(The echos are just there for debug reasons)

if (isset($_POST['aktion']) and $_POST['aktion']=='Annehmen') {    //button click
echo '<p>1</p>';
    $email = "";
    if (isset($_POST['email'])) {    //steht was da?
        $email = (INT) trim($_POST['email']);
    echo '<p>2</p>';
    if ($email != '') {    //steht was da? 2.0
        $suche = $db->prepare("SELECT email FROM recipients WHERE email = ?");
        $suche->bind_param('s', $email);
        $emailtest = "";
        $suche->execute();
        $suche->bind_result($emailtest);
        echo '<p>3</p>';
        if ($email == $emailtest){
            echo '<p>4</p>';
        }
    }
    }
}

The debug reaches "Milestone" 3, then its trace disappears, doesn't matter whether it's the right or wrong email.

THX for help in advance :).

Link to comment
Share on other sites

there's no need to compare, in php code, the column value fetched from the query with the column value being tested in the where clause. if the query matched a row(s) of data, the where clause was true.

next, if you are not actually using the row(s) of data that a query matches, i.e. you are only testing if a value exists or how many times it exists, use SELECT COUNT(*) ..., and if this is for a 'registration' script, where you are deciding if you are going to insert a row of data, instead, just define that column as a unique index, attempt to insert the data, then test if the query produced a duplicate error.

lastly, if you switch to the much simpler PDO database extension, a majority of the lines of code will go away.

Edited by mac_gyver
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.