سؤال

i am using php as i am doing some function by using pdo, i just want to verify the textbox data by comparing the data in the database. i am quite new to this pdo thing? can anyone provide some explanation or guide to assist me for further understanding? Just wondering am i doing correct for this few statement, and what to do in order to read and compare the data in the database?

if(isset($_POST['submit'])){
    if(!empty($row['Activation Code'])){
        $stmt = $db->prepare('SELECT ActivationCode FROM members WHERE ActivationCode = :ActivationCode');
        $stmt->execute(array(':ActivationCode' => $_POST['ActivationCode']));
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
    }
}
هل كانت مفيدة؟

المحلول

PDO::FETCH_ASSOC returns a row from the result set. The parameter PDO::FETCH_ASSOC tells PDO to return the result as an associative array.

The array keys will match your column names. If your table contains columns 'email' and 'password', the array will be structured like:

Array
(
    [ActivationCode] => 'this_is_code'

)

To read data from the 'ActivationCode' column, do:

$row['ActivationCode'];

How likely is returning only 1 record thus, if you want to compare something, you can use:

if($row['ActivationCode'] == 'xxxxx'){
    // your code
}

Font: PDO::FETCH_ASSOC

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top