twilitegxa Posted July 11, 2009 Share Posted July 11, 2009 I found another tutorial on the web for uploading files to a MySQL database, so it appears to work as far as saving the file name to my table in the database, but I have two more pages for displaying the list of files and then allowing you to download the files, but those pages are not working. The page that displays the files for downloading is displaying this error: Parse error: parse error in C:\wamp\www\displayimages.php on line 28 Here is the code for it: LIST IMAGES: <html> <head> <title>Download File From MySQL</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php //connect and select database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg",$conn) or die(mysql_error()); $query = "SELECT id, name FROM upload"; $result = mysql_query($query) or die('Error, query failed'); if(mysql_num_rows($result) == 0) { echo "Database is empty <br>"; } else { while(list($id, $name) = mysql_fetch_array($result)) { ?> <a href="download.php?id=<?php=$id;?>"><?php=$name;?></a> <br> </body> </html> And here is the page for downloading the images: DOWNLOAD IMAGES: <?php if(isset($_GET['id'])) { // if id is set then get the file with the id from database //connect and select database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg",$conn) or die(mysql_error()); $id = $_GET['id']; $query = "SELECT name, type, size, content " . "FROM upload WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$name"); echo $content; //close database connection exit; } ?> What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
celsoendo Posted July 11, 2009 Share Posted July 11, 2009 Missing 2 } on page that you are listing images. Quote Link to comment Share on other sites More sharing options...
ignace Posted July 11, 2009 Share Posted July 11, 2009 twilitegxa how is your rpg going? You have been working intensively on it, haven't you? I can somewhat follow your process just by going over your posts Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 11, 2009 Share Posted July 11, 2009 This is invalid syntax <a href="download.php?id=<?php=$id;?>"><?php=$name;?></a> <br> There is no <?php= tag (Only <?= when short tags is enabled). You should be using <?php echo $var; ?> Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted July 12, 2009 Author Share Posted July 12, 2009 I found one of the } I think that I was missing, but I don't see the other one. :-( Here is the revised code. What else am I missing? The error is saying: Parse error: parse error in C:\wamp\www\displayimages.php on line 20 Display List <html> <head> <title>Download File From MySQL</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php //connect and select database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg",$conn) or die(mysql_error()); $query = "SELECT id, name FROM upload"; $result = mysql_query($query) or die('Error, query failed'); if(mysql_num_rows($result) == 0) { echo "Database is empty <br>"; } else { while(list($id, $name) = mysql_fetch_array($result)) } ?> <a href="download.php?id=<?php echo $id; ?>"><?php echo $name; ?></a> <br> </body> </html> Download Images: <?php if(isset($_GET['id'])) { // if id is set then get the file with the id from database //connect and select database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg",$conn) or die(mysql_error()); $id = $_GET['id']; $query = "SELECT name, type, size, content " . "FROM upload WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$name"); echo $content; //close database connection exit; } ?> Am I missing anything else? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted July 12, 2009 Author Share Posted July 12, 2009 twilitegxa how is your rpg going? You have been working intensively on it, haven't you? I can somewhat follow your process just by going over your posts I messaged you about my RPG :-) Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted July 12, 2009 Share Posted July 12, 2009 This if(mysql_num_rows($result) == 0) { echo "Database is empty <br>"; } else { while(list($id, $name) = mysql_fetch_array($result)) } ?> <a href="download.php?id=<?php echo $id; ?>"><?php echo $name; ?></a> <br> Should be if(mysql_num_rows($result) == 0) { echo "Database is empty <br>"; } else { while(list($id, $name) = mysql_fetch_row($result)) { ?> <a href="download.php?id=<?php echo $id; ?>"><?php echo $name; ?></a> <br> <?php } } ?> Indenting you code makes it easier to read and maintain. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted July 13, 2009 Author Share Posted July 13, 2009 Thank you so much! That makes the code work perfectly! Thank you so much! 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.