L
L
LuidgiVamp2018-03-22 16:31:44
PHP
LuidgiVamp, 2018-03-22 16:31:44

Why doesn't function confirm change 0 to 1 in the database when confirming registration?

function confirm()
{
    global $db;
    $new_hash = clear_str($_GET['hash']);

    $query = "UPDATE . PREF .`users` SET confirm = '1' WHERE `hash` = '%s'";

    $query = sprintf($query, mysqli_real_escape_string($db, $new_hash));

    $resutl = mysqli_query($db, $query);


    if (mysqli_affected_rows($resutl) == 1) {
        return TRUE;
    } else {
        return "Не верный код подтверждения регистрации";
    }


}

?>

if($_GET['hash']) {

  $confirm = confirm();

  if($confirm === TRUE) {
    $_SESSION['msg'] = "Ваша учетная запись активирована. Можете авторизироваться нга сайте.";
    header("Location:".$_SERVER['PHP_SELF']);
    exit();
  }
}
else {
  $_SESSION['msg'] = $msg;
  header("Location:".$_SERVER['PHP_SELF']);
  exit();
}

Registration is successful, it sends a registration link, but then it is not possible to follow the link to successfully confirm the registration, what is the reason?

Answer the question

In order to leave comments, you need to log in

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

mysqli_affected_rows($db)
php.net/manual/ru/mysqli.affected-rows.php

L
LuidgiVamp, 2018-03-22
@LuidgiVamp

I already found an error, I just deleted the name localhost from the link that comes to the mail.
But now the error

function confirm()
{
    global $db;
    $new_hash = clear_str($_GET['hash']);

    $query = "UPDATE " . PREF . "users
        SET confirm='1'
        WHERE hash = '%s'
        ";
    $query = sprintf($query, mysqli_real_escape_string($db,$new_hash));

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

    if(mysqli_affected_rows() == 1){
        return TRUE;
    }
    else {
        return "Неверный код подтверждения регистрации";
    }


}

mysqli_affected_rows() expects parameter 1 to be mysqli
What parameter is it asking for?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question