nick.yem@gmail.com Posted May 26, 2007 Share Posted May 26, 2007 Hello mates, I have problem uploaded images to MYSQL and then of course viewing them. The MySQL table i use is the following: create table upload_image ( pid int primary key not null auto_increment, title text, imgdata longblob); The first PHP file is: <?php ?> <html> <head><title>Upload Image</title></head> <body> <?php if ($submit) { $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); } else { ?> <form method="post" action="confirm_results2.php" enctype="multipart/form-data"> File Description:<br> <input type="text" name="form_description" size="40"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> <br>File to upload/store in database:<br> <input type="file" name="form_data" size="40"> <p><input type="submit" name="submit" value="submit"> </form> <?php } ?> </body> </html> The second PHP is: <?php db_query("test","INSERT INTO upload_image VALUES('$_POST[form_description]','$_POST[form_data]')","no"); function db_query($select_database, $sql_query, $display_results) { $connect_to_db_server = mysql_connect('localhost', 'root', '323232'); $select_database = "test"; if (!$connect_to_db_server) { die('Could not connect: ' . mysql_error()); } if (!mysql_select_db($select_database)) { echo "There is no such select_database..."; } $result = mysql_query($sql_query); if($result) { echo "<b>Your DB query has been successfully completed</b>"; } else { echo "<b>Your DB query has been unsuccessful.<br> Please try again</b>"; } mysql_close($connect_to_db_server); if ($display_results != "no" && $result) { ?> <table border="3" align="center" width="35%" style="border-spacing: 3px; padding: 3em;"> <tr> <td bgcolor="lightblue" align="center" colspan="3"><font size="5">Your Details are: </font></td> </tr> <?php while ($row= mysql_fetch_array($result)) { ?> <tr> <td bgcolor="lightblue" align="center"><?php echo $fname = $row["fname"]."<br>"; ?></td> <td bgcolor="lightblue" align="center"><?php echo $lname = $row["lname"]."<br>"; ?></td> <td bgcolor="lightblue" align="center"><?php echo $sex = $row["sex"]."<br>"; ?></td> </tr> <?php } ?></table><?php } } ?> Any IDEAS why this does not work? Quote Link to comment https://forums.phpfreaks.com/topic/53045-upload-images-to-mysql/ Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 Please use code tags please ask a question correctly (see my signature) Quote Link to comment https://forums.phpfreaks.com/topic/53045-upload-images-to-mysql/#findComment-262067 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.