RCS Posted March 31, 2008 Share Posted March 31, 2008 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("dbstuff.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> </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_file.php?id=<?php echo $id; ?>"><?php echo $name;?>[/url] </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!! Link to comment https://forums.phpfreaks.com/topic/98842-upload-and-post-image-with-mysql/ Share on other sites More sharing options...
RCS Posted March 31, 2008 Author Share Posted March 31, 2008 echo "<td><img src='http://www.refinedcomputersolutions.com/php_scripts/tmpName/'" . $row['name'] . "</td>"; and not echo "<td>" . $row['name'] . "</td>"; I tried that and just get a blank icon and yes image is in the directory path. ?????????????????????????????????????????????????? ?????????????????????? If someone could help me that would be great. Link to comment https://forums.phpfreaks.com/topic/98842-upload-and-post-image-with-mysql/#findComment-505782 Share on other sites More sharing options...
RCS Posted March 31, 2008 Author Share Posted March 31, 2008 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 to a catalog page. Can someone please tell me how I can do this?????? Link to comment https://forums.phpfreaks.com/topic/98842-upload-and-post-image-with-mysql/#findComment-505788 Share on other sites More sharing options...
RCS Posted March 31, 2008 Author Share Posted March 31, 2008 http://refinedcomputersolutions.com:8080/php_script/download_file.php http://refinedcomputersolutions.com:8080/php_script/form.php Just image info seems to be stored to database so I included a path to a directory where I saved the images. http://www.refinedcomputersolutions.com/php_scripts/tmpName/ my database looks like this CREATE TABLE upload ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(30) NOT NULL, type VARCHAR(30) NOT NULL, size INT NOT NULL, description VARCHAR(350) NOT NULL, price VARCHAR(128) NOT NULL, make VARCHAR(30) NOT NULL, category VARCHAR(30) NOT NULL, content MEDIUMBLOB NOT NULL, PRIMARY KEY(id) ); e.g Make, "Opel" Description, "4 Wheels, Very Big" Price, 9995 Picture, 001.jpg the actual picture not the picture name. Link to comment https://forums.phpfreaks.com/topic/98842-upload-and-post-image-with-mysql/#findComment-505815 Share on other sites More sharing options...
RCS Posted March 31, 2008 Author Share Posted March 31, 2008 I figured it out my self All I hade to do was change code to echo "<td><img src =\"" . $row['name']."\"></td>"; lol so simple. Link to comment https://forums.phpfreaks.com/topic/98842-upload-and-post-image-with-mysql/#findComment-505904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.