I'm sorry for that code above that occasionally is not working :)
This one should exactly work:
<html><head><meta charset="utf-8"></head>
if (
isset($_POST['title'])&&
isset($_POST['category'])&&
isset($_POST['name'])&&
isset($_POST['telno'])&&
isset($_POST['price'])&&
isset($_POST['info']))
{
$connection=new mysqli($db_hostname, $db_username, $db_password, $db_database);
if($connection->connect_error) die($connection->connect_error);
$title = $_POST['title'];
$category = $_POST['category'];
$name = $_POST['name'];
$telno = $_POST['telno'];
$price = $_POST['price'];
$info = $_POST['info'];
if (($img_data = file_get_contents($_FILES['img1']['tmp_name'])) &&
is_uploaded_file($_FILES['img1']['tmp_name']))
{
$query="INSERT INTO avto (title, category, img1, name, telno, price, info)
VALUES ('$title', '$category', '".base64_encode($img_data)."',
'$name', '$telno', '$price', '$info')";
$result = $connection->query($query);
if(!$result) echo "Кушиб булмаяпти: $query<br>";
}
$query="SELECT * FROM avto";
$result=$connection->query($query);
If (!$result) die ($connection->error);
$rows=$result->num_rows;
for ($j=0;$j<$rows;++$j)
{
$result->data_seek($j);
$row=$result->fetch_array(MYSQLI_BOTH);
echo "<img src="data:image/gif;base64,".$row[3].""></img>";
}
$result->close();
$connection->close();
function get_post($connection, $var)
{
return $connection->real_escape_string($_POST[$var]);
}
}?>
<form action="index.php" method="post" enctype="multipart/form-data">
Title <input type="text" name="title">
Category <input type="text" name="category">
Main img <input type="file" name="img1" >
Name <input type="text" name="name">
Tel NO <input type="text" name="telno">
Price <input type="text" name="price">
Info <textarea rows="6" cols="30" name="info"></textarea>
<input type="submit" value="Submit">
</form>
</html>
Here's the sql dump for the database this code is working with:
;
;
;
;
CREATE DATABASE IF NOT EXISTS `images` ;
USE `images`;
CREATE TABLE IF NOT EXISTS `avto` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL,
`category` varchar(50) NOT NULL,
`img1` longblob NOT NULL,
`name` varchar(50) NOT NULL,
`telno` varchar(50) NOT NULL,
`price` varchar(50) NOT NULL,
`info` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
;
;
;
;
;
P.S. Don't forget to specify the correct path to the temporary files uploaded in php.ini:
file_uploads = On
upload_tmp_dir = h:\temp