Hi everyone, I'm trying to create a script where I can save form data e.g Make, Description, Price, Picture
after saving data to mysql I want to post it by id to a catalog page. I'm having an issue with getting image from database.
I can't seem to figure it out. If someone could help me it would be greatly appreciated.
Thank you very much in advance.
This is form
<html>
<body><form action="upload_file.php" method="POST"
enctype="multipart/form-data">
<p><label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<input type="hidden" name="MAX_FILE_SIZE" value="100000000000000"></p>
<p><label>
Make:</label>
<input type="text" name="make" id="make" /></p>
<p><label>
Price:</label>
<input type="text" name="price" id="price" /></p>
<p><label>
Category:</label>
<input type="text" name="category" id="category" /></p>
<p><label>
Description:</label>
<textarea name="description" id="description" cols="45" rows="5"></textarea /></p>
<input type="submit" name="submit" value="Submit" />
</form></body>
</html>
This is upload page where everything gets saved to database
<?php
include("dbinfo.inc");
include("file_array.inc");
if(isset($_POST['upload']) && $_FILES['file']['size'] > 0)
{
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
}
$con = mysqli_connect($db_host, $db_user, $db_passwd, $db_name);
$query = "INSERT INTO upload(name, size, type, content, make, price, description)".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content','$_POST[make]','$_POST[price]','$_POST[description]')";
$result=mysqli_query($con, $query) or die ("Could not complete query.");
mysql_close($con);
?>
<html>
<head><title>CMS</title></head>
<body><center>
Information successfuly saved to database.</center></body>
</html>
This is page where data gets posted
<html>
<head>
<title>Download File From MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
include("dbinfo.inc");
$con = mysqli_connect($db_host, $db_user, $db_passwd, $db_name);
$query = ("SELECT * FROM upload ORDER BY id");
$result = mysqli_query($con, $query) or die('Error, query failed');
echo "<table border='1'>
<tr>
<th>Make</th>
<th>Description</th>
<th>Price</th>
<th>Picture</th>
</tr>";
while($row = mysqli_fetch_array ($result))
{
echo "<tr>";
echo "<td>" . $row['make'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "</tr>";
}
echo "</table>";mysqli_close($con);
?>
<a href="download.php?id=<?php echo $id; ?>"><?php echo $name;?>[/url]
<?php
mysql_close($con);
?>
</body>
</html>
This is file_array
<?php
$fileName = $_FILES['file']['name'];
$tmpName = $_FILES['file']['tmpName'];
$fileSize = $_FILES['file']['size'];
$fileType = $_FILES['file']['type'];
?>
Don't laugh to hard!!
