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><b>Make:</b></label> <input type="text" name="make" id="make" /></p> <p><label><b>Price:</b></label> <input type="text" name="price" id="price" /></p> <p><label><b>Category:</b></label> <input type="text" name="category" id="category" /></p> <p><label><b>Description:</b></label> <textarea name="description" id="description" cols="45" rows="5"></textarea /></p> <br /> <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><b>Information successfuly saved to database.</b></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;?></a><br> <?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!! Quote Link to comment Share on other sites More sharing options...
wmguk Posted March 31, 2008 Share Posted March 31, 2008 wow, thats a script! urm, sorry to sound really stupid but im not sure exactly what you are trying to do, where is the image info currently found? Quote Link to comment Share on other sites More sharing options...
RCS Posted March 31, 2008 Author Share Posted March 31, 2008 Well my database is 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) ); Quote Link to comment Share on other sites More sharing options...
wmguk Posted March 31, 2008 Share Posted March 31, 2008 ok, Have I got the wrong end of this stick? when you say getting an image from the database, what are you expecting to see? Well my database is 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) ); Quote Link to comment Share on other sites More sharing options...
RCS Posted March 31, 2008 Author Share Posted March 31, 2008 do I have to some how save the file to a location and not the database?? I just don't understand ??????????????????????? It seems to save the file info to database so wouldn't that mean that file is saved. If so how do I display it with the other info e.g make, description, price ?????????????????????????????????????????????????????????????? Quote Link to comment Share on other sites More sharing options...
wmguk Posted March 31, 2008 Share Posted March 31, 2008 hmm, im lost on this one, im only a bit of a novice really, but sometimes a pair of fresh eyes see's it straight away, I think this is over my head Sorry i couldnt help you more I do I have to some how save the file to a location and not the database?? I just don't understand ??????????????????????? It seems to save the file info to database so wouldn't that mean that file is saved. If so how do I display it with the other info e.g make, description, price ?????????????????????????????????????????????????????????????? Quote Link to comment Share on other sites More sharing options...
RCS Posted March 31, 2008 Author Share Posted March 31, 2008 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. Can you tell me how to do this?? Quote Link to comment Share on other sites More sharing options...
wmguk Posted March 31, 2008 Share Posted March 31, 2008 oh ok, so you are literally just wanting to display say ID 1 on a page? so ID1 Make, "Opel" Description, "4 Wheels, Very Big" Price, 9995 Picture, 001.jpg and repeat it through the page? Quote Link to comment Share on other sites More sharing options...
RCS Posted March 31, 2008 Author Share Posted March 31, 2008 yes it would just save make, description, price, picture to a page <a href="download.php?id=<?php echo $id; ?>"><?php echo $name;?>[/url] should not even be their I just want it to keep posting that data to a page everytime I submit the form. Quote Link to comment Share on other sites More sharing options...
RCS Posted March 31, 2008 Author Share Posted March 31, 2008 see the way it works now is that it will post Make Description Price and image name not actual image and I need the actual image. Quote Link to comment Share on other sites More sharing options...
RCS Posted March 31, 2008 Author Share Posted March 31, 2008 Like this Make Description Price Picture RV TESTING RV DATABASE FOR ERROR. 123445 rv.jpg just image name not the image and I want the image to be displayed Quote Link to comment Share on other sites More sharing options...
wmguk Posted March 31, 2008 Share Posted March 31, 2008 ok, to display the actual image you will need the img tag echo "<td>" . $row['name'] . "</td>"; try echo "<td><img src='http://www.domain.tld/images/'" . $row['name'] . "</td>"; Quote Link to comment Share on other sites More sharing options...
RCS Posted March 31, 2008 Author Share Posted March 31, 2008 now I just have a blank image icon and I have added all images to the directory, not sure why it will not display it? ??????????????????????????????????????????????????????????????????????????????????????/ Quote Link to comment Share on other sites More sharing options...
wmguk Posted March 31, 2008 Share Posted March 31, 2008 whats is the location of the script and the location of the image directory? i'll have a look for you Quote Link to comment Share on other sites More sharing options...
RCS Posted March 31, 2008 Author Share Posted March 31, 2008 what do yoou need?? Quote Link to comment 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 image directory http://refinedcomputersolutions.com:8080/php_script/tmpName/ Quote Link to comment Share on other sites More sharing options...
RCS Posted March 31, 2008 Author Share Posted March 31, 2008 http://refinedcomputersolutions.com:8080/php_script/form.php Quote Link to comment Share on other sites More sharing options...
wmguk Posted March 31, 2008 Share Posted March 31, 2008 http://refinedcomputersolutions.com:8080/php_script/download_file.php image directory http://refinedcomputersolutions.com:8080/php_script/tmpName/ can you show the script you are using for download_file.php please? Quote Link to comment Share on other sites More sharing options...
RCS Posted March 31, 2008 Author Share Posted March 31, 2008 <?php /** * Keith Maki, RCS */ ?> <html> <head> <title>Download File From MySQL</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php include("dbstuff.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><img src='http://www.refinedcomputersolutions.com/php_scripts/tmpName/'" . $row['name'] . "</td>"; echo "</tr>"; } echo "</table>";mysqli_close($con); ?> <a href="download.php?id=<?php echo $id; ?>"><?php echo $name;?></a><br> <?php mysql_close($con); ?> </body> </html> Quote Link to comment 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. Thanks for trying. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.