I'm beginner in php and I have a problem that I can not explain by myself.. I have two files: the first one index.html:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="post">
<input name="file" type="file"/>
<input type="submit" value="Wyslij" />
</form>
</body>
</html>
and the second one upload.php:
<?php
if(isset($_FILES['file'])){
$db=new mysqli('localhost','root','kursphp','products');
$name= $db->real_escape_string($_FILES['file']['name']);
$type=$db->real_escape_string($_FILES['file']['type']);
$data=$db->real_escape_string(file_get_contents($_FILES['file']['tmp_name']));
$size=intval($_FILES['file']['size']);
//question
$query= "INSERT INFO files(name,type,size,data,created) VALUES ('{$name}','{$type}','{$size}','{$data}',NOW())";
$result=$db->query($query);
if($result){
echo "File saved";
} else {
echo $db->error();
}
$db->close();
}
?>
When I upload some file, I get an error:
Fatal error: Call to undefined method mysqli::error() in D:\wamp\www\php_z\upload\upload.php on line 20
I don't know why I get this kind of error because as I declared: db is an object of mysqli. I read in documentation of PHP that
mysqli::$error -- mysqli_error — Returns a string description of the last error
So there is method such error()
.. Can someone tell me how to fix this?