문제

I have been working on something which a friend asked me. He is using ezsql for his queries and i'm pretty new with it. Though i used it in the same project.

Here is the database columns and data to see it clearly enter image description here

And the part of the code which fails:

    $customsql = new ezSQL_mysql();
    $customsql->query("SET NAMES 'utf8'"); 
    $customsql->query("SELECT * FROM uyeler WHERE email='".escape($_POST['eposta'])."' AND sifre='".escape($_POST['sifre'])."'");
    if($customsql->num_rows>0){
        if($customsql->onay=='1'){
            //Things to do if user is activated.
        }else{
            $hata='Onay:'.$customsql->onay.' -Error: Bu eposta adresiyle kayıtlı onaylanmamış bir kullanıcı var. Lütfen epostanızı onaylayın.';
            $_SESSION['loggedin']=FALSE;
        }

"onay" is varchar in database. And here is the result: enter image description here

While it is working in registration process, why doesn't it work here?

Thanks in advance.

도움이 되었습니까?

해결책

I found the problem. There were 2 mistakes above.

1- Assign query results to a variable.

2- "get_results" if you are expecting more than one row from your query. ("get_row" if you want just one row and "get_var" if you query for just one column instead of *)

Here is how you should use the query which you need results from:

$customsql = new ezSQL_mysql();
$customsql->query("SET NAMES 'utf8'"); 
$yourvariable=$customsql->get_row("SELECT * FROM uyeler WHERE email='".escape($_POST['eposta'])."' AND sifre='".escape($_POST['sifre'])."'");
if($customsql->num_rows>0){
    if($yourvariable->onay=='1'){
        //Things to do if user is activated.
    }else{
        $hata='Onay:'.$customsql->onay.' -Error: Bu eposta adresiyle kayıtlı onaylanmamış bir kullanıcı var. Lütfen epostanızı onaylayın.';
        $_SESSION['loggedin']=FALSE;
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top