в директорию добавляет аватары, а в базу данных нет.
формы и их обработка
<?php
session_start();
require_once('function_userdata.php');
print_r($_SESSION['id']);
if(isset($_POST['editavatar']))
$avatar = $_FILES["avatar"];
if (isSecurity($avatar)) loadavatar($avatar, $_SESSION["login"]);
else $message = "error download";
?>
<html xmlns ="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "Content-Type" content = "text/html"; charset = "utf-8"/>
<title>Profil redaction</title>
</head>
<body>
<br />
<br />
<table border ='1' width='100%' cellpadding = '0' cellspasing = '0'>
<div style = "text-align: center;">
<h1> upload avatar </h1>
<form id="formedit" action="avatarrusakov.php" method="post" class="content" enctype="multipart/form-data">
<p> <input type="file" name="avatar"> </p>
<p> <input type="submit" name="editavatar" value="change"> </p>
</form>
</div>
</table>
</body>
</head>
</html>
функции
function isSecurity ($avatar){
$name = $avatar["name"];
$type = $avatar["type"];
$size = $avatar["size"];
$blacklist = array (".php", ".phtml", ".php3", ".php4");
foreach ($blacklist as $item){
if (preg_match("/$item\$/i", $name)) return false;
}
if(($type !="image/gif") && ($type !="image/png") && ($type !="image/jpg") && ($type !="image/jpeg")) return false;
if($size> 20 * 1024 * 1024) return false;
return true;
}
function loadAvatar($avatar, $login)
{
$type = $avatar["type"];
$uploaddir = "avatars/";
$name = md5(microtime()).".".substr($type, strlen("image/"));
$uploadfile = $uploaddir.$name;
if (move_uploaded_file($avatar["tmp_name"], $uploadfile)) {
setAvatar($login, $name);
return true;
}
else return false;
}
function setAvatar($login, $name)
{
$mysql = connect_db();
$mysql->query("UPDATE `reg_users` SET `avatar`='$name' WHERE `login`='$login'" );
}
в сет аватар выдает ошибку - Fatal error: Call to a member function query() on a non-object in Z:\home\veterinar.com\www\function_userdata.php on line 151
function getavatar($login)
{
connect_db();
$result_set =mysql_query("SELECT `avatar` FROM `users` WHERE `login`='$login'");
$row = $result_set ->fetch_assoc();
return $row["avatar"];
}
?>