L
L
LuidgiVamp2018-03-23 13:19:39
PHP
LuidgiVamp, 2018-03-23 13:19:39

How to correctly write mysql_result to mysqli?

function login($post)
{

    global $db;
    if (empty($post['login']) || empty($post['password'])) {
        return "Заполните поля";
    }

    $login = clear_str($post['login']);
    $password = md5(trim($post['password']));

    $sql = "SELECT user_id,confirm
      FROM " . PREF . "users
      WHERE login = '%s'
      AND password = '%s'";
    $sql = sprintf($sql, mysqli_real_escape_string($db, $login), $password);

    $result = mysqli_query($db, $sql);

    if (!$result || mysqli_num_rows($result) < 1) {
        return "Не правильный логи или пароль";
    }
    <b>if (mysqli_result($result, 0, 'confirm') == 0) {
        return "Пользователь с таким логином еще не продтвержден";
    }</b>

    $sess = md5(microtime());

    $sql_update = "UPDATE " . PREF . "users SET sess='$sess' WHERE login='%s'";
    $sql_update = sprintf($sql_update, mysqli_real_escape_string($db, $login));

    if (!mysqli_query($db, $sql_update)) {
        return "Ошибка авторизации пользователя";
    }

    $_SESSION['sess'] = $sess;

    if ($post['member'] == 1) {
        $time = time() + 10 * 24 * 3600;

        setcookie('login', $login, $time);
        setcookie('password', $password, $time);

    }

    return TRUE;
}

if (mysqli_result($result, 0, 'confirm') == 0) {
return "User with this login has not yet been confirmed";
}

how to write down this line correctly? - if (mysqli_result($result, 0, 'confirm') == 0)
gives

Uncaught Error: Call to undefined function mysqli_result() in C:\Server\domains\1234\functions.php:180 Stack trace: #0 C:\Server\domains\1234\actions\login.php(5): login(Array) #1 C:\Server\domains\1234\index.php(21): include('C:\\Server\\ domai...') #2 {main} thrown in C:\Server\domains\1234\functions.php on line
180
if ($post['member'] == 1) {
        $time = time() + 10 * 24 * 3600;

        setcookie('login', $login, $time);
        setcookie('password', $password, $time);

    }

Here is this function to remember the entered data login and password

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LuidgiVamp, 2018-03-23
@LuidgiVamp

if(mysqli_fetch_assoc($result)['confirm'] == 0) {
        return ("Пользователь с таким логином еще не продтвержден");
    }

Here is the correct code!

D
Dlive1989, 2020-05-24
@Dlive1989

//Looks like this condition doesn't work either. at least for me.
//Here is an analogue of mysql_result($result,0) :
//Create a function side by side at the top:
function mysqli_result($res,$row=0,$col=0){
$numrows = mysqli_num_rows($res);
if ($numrows && $row <= ($numrows-1) && $row >=0){
mysqli_data_seek($res,$row);
$resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
if (isset($resrow[$col])){
return $resrow[$col];
}
}
return false;
}
//Then we write our result:
if(mysqli_result($result,0)==0) { //mysqli_result
return ("The user with this login has not yet been verified");
}
//in theory, it should work if you didn't confuse equality with != (not equal) in the condition
//Good luck!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question