se añadieron 2893 caracteres en el cuerpo; título editado
Origen Enlace
sode
  • 161
  • 11

Error con una consulta PHP MYsqliy MySqli

Este es el codigo conmpreto:

========== Funcion para los carateles UTF-8

 function PHP_Secure($string, $censored_words = 1) {
        global $db;
        $string = trim($string);
        $string = mysqli_real_escape_string($db, $string);
        $string = htmlspecialchars($string, ENT_QUOTES,'UTF-8');
        $string = str_replace('\r\n', " <br>", $string);
        $string = str_replace('\n\r', " <br>", $string);
        $string = str_replace('\r', " <br>", $string);
        $string = str_replace('\n', " <br>", $string);
        $string = str_replace('&amp;#', '&#', $string);
        $string = stripslashes($string);
        if ($censored_words == 1) {
            global $config;
            $censored_words = @explode(",", $config['censored_words']);
            foreach ($censored_words as $censored_word) {
                $censored_word = trim($censored_word);
                $string        = str_replace($censored_word, '****', $string);
            }
        }
        return $string;
    }

========== Funcion del login

    function system_login() {
    
        global $con;
        if (@$_COOKIE["muser"]!='') {
        @header("Location:./");
        exit('<meta http-equiv="Refresh" content="0;url=./">');
        }
        if (!empty($_POST)) {
    
    $username        = PHP_Secure($_POST['username']);
            $password        = PHP_Secure($_POST['password']);
            $password_hashed = sha1($password);
        // EN ESTA LINIA ME DA EL ERROR
            $db->where("(username = ?)", array(
                $username
            ));
// EN ESTA LINIA ME DA EL ERROR
            $db->where("password", $password_hashed);
            $login = $db->getOne(T_USERS);
            if (!empty($login)) {
                if ($login->active == 0) {
                    $errors = 'ERROR';
                } else {
                    $session_id          = sha1(rand(11111, 99999)) . time() . md5(microtime());
                    $insert_data         = array(
                        'user_id' => $login->id,
                        'session_id' => $session_id,
                        'time' => time()
                    );
                    $insert              = $db->insert(T_SESSIONS, $insert_data);
                    $_SESSION['user_id'] = $session_id;
                    setcookie("user_id", $session_id, time() + (10 * 365 * 24 * 60 * 60));
                    $pt->loggedin = true;
                    if (!empty($_GET['to'])) {
                        $site_url = $_GET['to'];
                    }
                    header("Location: $site_url");
                    exit();
                }
        }
    }

Error con una consulta PHP MYsqli

Error con una consulta PHP y MySqli

Este es el codigo conmpreto:

========== Funcion para los carateles UTF-8

 function PHP_Secure($string, $censored_words = 1) {
        global $db;
        $string = trim($string);
        $string = mysqli_real_escape_string($db, $string);
        $string = htmlspecialchars($string, ENT_QUOTES,'UTF-8');
        $string = str_replace('\r\n', " <br>", $string);
        $string = str_replace('\n\r', " <br>", $string);
        $string = str_replace('\r', " <br>", $string);
        $string = str_replace('\n', " <br>", $string);
        $string = str_replace('&amp;#', '&#', $string);
        $string = stripslashes($string);
        if ($censored_words == 1) {
            global $config;
            $censored_words = @explode(",", $config['censored_words']);
            foreach ($censored_words as $censored_word) {
                $censored_word = trim($censored_word);
                $string        = str_replace($censored_word, '****', $string);
            }
        }
        return $string;
    }

========== Funcion del login

    function system_login() {
    
        global $con;
        if (@$_COOKIE["muser"]!='') {
        @header("Location:./");
        exit('<meta http-equiv="Refresh" content="0;url=./">');
        }
        if (!empty($_POST)) {
    
    $username        = PHP_Secure($_POST['username']);
            $password        = PHP_Secure($_POST['password']);
            $password_hashed = sha1($password);
        // EN ESTA LINIA ME DA EL ERROR
            $db->where("(username = ?)", array(
                $username
            ));
// EN ESTA LINIA ME DA EL ERROR
            $db->where("password", $password_hashed);
            $login = $db->getOne(T_USERS);
            if (!empty($login)) {
                if ($login->active == 0) {
                    $errors = 'ERROR';
                } else {
                    $session_id          = sha1(rand(11111, 99999)) . time() . md5(microtime());
                    $insert_data         = array(
                        'user_id' => $login->id,
                        'session_id' => $session_id,
                        'time' => time()
                    );
                    $insert              = $db->insert(T_SESSIONS, $insert_data);
                    $_SESSION['user_id'] = $session_id;
                    setcookie("user_id", $session_id, time() + (10 * 365 * 24 * 60 * 60));
                    $pt->loggedin = true;
                    if (!empty($_GET['to'])) {
                        $site_url = $_GET['to'];
                    }
                    header("Location: $site_url");
                    exit();
                }
        }
    }
Origen Enlace
sode
  • 161
  • 11

Error con una consulta PHP MYsqli

tengo un problema cuando hago una consulta me da un error que no conosco y ni se el porque me pasa esto me dice algo con una funcion llamada stdClass y hice esta funcion para ver si asi funcionaba pero no, que puedo hacer en este caso?

function ToObject($array) {
    $object = new stdClass();
    foreach ($array as $key => $value) {
        if (is_array($value)) {
            $value = ToObject($value);
        }
        if (isset($value)) {
            $object->$key = $value;
        }
    }
    return $object;
}

Fatal error: Uncaught Error: Cannot use object of type stdClass as array in C:\xampp\htdocs\one_2\application\includes\login.php:69 Stack trace: #0 C:\xampp\htdocs\one_2\application\system\system_function.php(16): require() #1 C:\xampp\htdocs\one_2\application\Connection.php(12): require_once('C:\xampp\htdocs...') #2 C:\xampp\htdocs\one_2\index.php(2): require_once('C:\xampp\htdocs...') #3 {main} thrown in C:\xampp\htdocs\one_2\application\includes\login.php on line 69

sistema que estoy usando para esto es

PHP-MySQLi-Database-Class: https://github.com/ThingEngineer/PHP-MySQLi-Database-Class

Conexion:

$mysqli = new mysqli($dbhost, $dbuser, $dbpassword, $dbdatabase);
$query = $mysqli->query("SET NAMES utf8");
$mysqli->set_charset("utf8");
// Connecting to DB after verfication
$db = new MysqliDb($mysqli);

Este es el codigo basico:

$db->where ("userID", 1);
$user = $db->getOne ("user");
echo $user['user'];