Я не могу найти ошибку в php. Иногда такая ошибка:
Предупреждение: array_walk () ожидает, что параметр 2 будет действительным обратным вызовом, функция «array_sanitize» не найдена или неверное имя функции в Z: \ home \ site.kz \ www \ core \ functions \ users.php в строке 3
- используя jquery $ .ajax для вызова функции PHP
- Обновление проблем с созданием простой Php, MySql Voting System
- Многоуровневый доступ к массиву PHP
- Symfony2- Форма входа снова появляется после входа в систему
- Добавить X дней до даты, исключая выходные
Предупреждение: mysqli_query () ожидает, что параметр 1 будет mysqli, null указан в Z: \ home \ site.kz \ www \ core \ functions \ users.php в строке 10
Предупреждение: mysqli_insert_id () ожидает, что параметр 1 будет mysqli, null указан в Z: \ home \ site.kz \ www \ core \ functions \ users.php в строке 11
Предупреждение: mysqli_query () ожидает, что параметр 1 будет mysqli, null указан в Z: \ home \ site.kz \ www \ core \ functions \ users.php в строке 13
<?php function register_user($register_data) { array_walk($register_data, 'array_sanitize'); $register_data['password'] = md5($register_data['password']); $fields = '`' . implode('`, `', array_keys($register_data)) . '`'; $data = '\'' . implode('\', \'', $register_data) . '\''; $insert = "INSERT INTO users($fields) VALUES ($data) "; mysqli_query($con,$insert); $last_id = mysqli_insert_id($con); $update = "UPDATE users SET url = '".$last_id."' WHERE id = ".$last_id." "; mysqli_query($con,$update ); } ?>
ОБНОВИТЬ
Полный код:
init.php
<?php session_start(); error_reporting(0); require 'database/connect.php'; require 'functions/languages.php'; require 'functions/general.php'; require 'functions/users.php'; if (logged_in() === true) { $session_id = $_SESSION['id']; $user_data = user_data($session_id, 'id', 'username', 'password', 'first_name', 'last_name', 'email'); } $errors = array(); ?>
users.php
Старый код:
function register_user($register_data) { array_walk($register_data, 'array_sanitize'); $register_data['password'] = md5($register_data['password']); $fields = '`' . implode('`, `', array_keys($register_data)) . '`'; $data = '\'' . implode('\', \'', $register_data) . '\''; mysql_query("INSERT INTO `users` ($fields) VALUES ($data)"); }
<?php function register_user($register_data) { array_walk($register_data, 'array_sanitize'); $register_data['password'] = md5($register_data['password']); $fields = '`' . implode('`, `', array_keys($register_data)) . '`'; $data = '\'' . implode('\', \'', $register_data) . '\''; $insert = "INSERT INTO users($fields) VALUES ($data) "; mysqli_query($con,$insert); $last_id = mysqli_insert_id($con); $update = "UPDATE users SET url = '".$last_id."' WHERE id = ".$last_id." "; mysqli_query($con,$update ); } function user_count() { return mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `active` = 1"), 0); } function user_data($id) { $data = array(); $id = (int)$id; $func_num_args = func_num_args(); $func_get_args = func_get_args(); if ($func_num_args > 1) { unset($func_get_args[0]); $fields = '`' . implode('`, `', $func_get_args) . '`'; $data = mysql_fetch_assoc(mysql_query("SELECT $fields FROM `users` WHERE `id` = $id")); return $data; } } function logged_in() { return (isset($_SESSION['id'])) ? true : false; } function user_exists($username) { $username = sanitize($username); return (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `username` = '$username'"), 0) == 1) ? true : false; } function email_exists($email) { $email = sanitize($email); return (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `email` = '$email'"), 0) == 1) ? true : false; } function user_active($username) { $username = sanitize($username); return (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `username` = '$username' AND `active` = 1"), 0) == 1) ? true : false; } function id_from_username($username) { $username = sanitize($username); return mysql_result(mysql_query("SELECT `id` FROM `users` WHERE `username` = '$username'"), 0, 'id'); } function login($username, $password) { $id = id_from_username($username); $username = sanitize($username); $password = md5($password); return (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"), 0) == 1) ? $id : false; } ?>
не<?php function register_user($register_data) { array_walk($register_data, 'array_sanitize'); $register_data['password'] = md5($register_data['password']); $fields = '`' . implode('`, `', array_keys($register_data)) . '`'; $data = '\'' . implode('\', \'', $register_data) . '\''; $insert = "INSERT INTO users($fields) VALUES ($data) "; mysqli_query($con,$insert); $last_id = mysqli_insert_id($con); $update = "UPDATE users SET url = '".$last_id."' WHERE id = ".$last_id." "; mysqli_query($con,$update ); } function user_count() { return mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `active` = 1"), 0); } function user_data($id) { $data = array(); $id = (int)$id; $func_num_args = func_num_args(); $func_get_args = func_get_args(); if ($func_num_args > 1) { unset($func_get_args[0]); $fields = '`' . implode('`, `', $func_get_args) . '`'; $data = mysql_fetch_assoc(mysql_query("SELECT $fields FROM `users` WHERE `id` = $id")); return $data; } } function logged_in() { return (isset($_SESSION['id'])) ? true : false; } function user_exists($username) { $username = sanitize($username); return (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `username` = '$username'"), 0) == 1) ? true : false; } function email_exists($email) { $email = sanitize($email); return (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `email` = '$email'"), 0) == 1) ? true : false; } function user_active($username) { $username = sanitize($username); return (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `username` = '$username' AND `active` = 1"), 0) == 1) ? true : false; } function id_from_username($username) { $username = sanitize($username); return mysql_result(mysql_query("SELECT `id` FROM `users` WHERE `username` = '$username'"), 0, 'id'); } function login($username, $password) { $id = id_from_username($username); $username = sanitize($username); $password = md5($password); return (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'"), 0) == 1) ? $id : false; } ?>
general.php
<?php function protect_page() { if (logged_in() === false) { header('Location: protected.php'); } } function aray_sanitize(&$item) { $item = mysql_real_escape_string($item); } function sanitize($data) { return mysql_real_escape_string($data); } function output_errors($errors) { return '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>'; } ?>
connect.php
<?php $host="Localhost"; $db="social"; $user="social"; $password="social"; $connect_error = 'Sorry, we\'re experiencing connection problems.'; mysql_connect($host, $user, $password) or die($connect_error); mysql_select_db($db) or die($connect_error); ?>
Попробуй это:
function register_user($register_data) { global $con; array_walk($register_data, 'array_sanitize'); $register_data['password'] = md5($register_data['password']); $fields = '`' . implode('`, `', array_keys($register_data)) . '`'; $data = '\'' . implode('\', \'', $register_data) . '\''; $insert = "INSERT INTO users($fields) VALUES ($data) "; mysqli_query($con,$insert); $last_id = mysqli_insert_id($con); $update = "UPDATE users SET url = '".$last_id."' WHERE id = ".$last_id." "; mysqli_query($con,$update ); } function aray_sanitize(&$item) { $item = mysql_real_escape_string($item); }