daebat Posted October 15, 2009 Share Posted October 15, 2009 I have a form that I have created and so far everything works except uploading images. Here is my code: <? include("../include/session.php"); ?> <?php if ($submit) { $sql = "UPDATE productimages SET title='".$_POST['title']."', upjpg='".$_POST['upjpg']."', uptiff='".$_POST['uptiff']."', uppng='".$_POST['uppng']."', category='".$_POST['category']."', upthumb='".$_POST['upthumb']."' where id ='".mysql_real_escape_string($_POST['id'])."'"; $result = mysql_query($sql) or die(mysql_error()); print("Product Added"); } print (" <form method=post action=productimages.php> Product Title:<br> <input type=text name=title size=60><br><br> Category:<br> <select name='category'> <option value='1'>Akaishi</option> <option value='2'>Balance Walking</option> <option value='8'>Bellamargiano</option> <option value='3'>Chung Shi</option> <option value='4'>Reebok</option> <option value='5'>Stretchwalker</option> <option value='6'>To The Point</option> <option value='7'>Xensible</option> </select> <table width=500 cellpadding=0 cellspacing=0> <tr><td colspan=2 class=top><br /><strong>Images</strong></td></tr> <tr><td>Upload JPG</td><td><br><input type=file name=upjpg></td></tr> <tr><td colspan=2 class=top> </td></tr> <tr><td>Upload TIFF</td><td><br><input type=file name=uptiff> </td></tr> <tr><td colspan=2 class=top> </td></tr> <tr><td>Upload PNG</td><td><br><input type=file name=uppng> </td></tr> <tr><td colspan=2 class=top> </td></tr> <tr><td>Upload Thumbnail</td><td><br><input type=file name=upthumb> </td></tr> </table> <br> <input type=submit name=submit value=submit><br> <br> </form> "); } ?> Link to comment https://forums.phpfreaks.com/topic/177778-image-upload/ Share on other sites More sharing options...
dymon Posted October 15, 2009 Share Posted October 15, 2009 To the form tag add: enctype="multipart/form-data", to be able to upload files. In PHP use $_FILES to get the files you uploaded. Link to comment https://forums.phpfreaks.com/topic/177778-image-upload/#findComment-937408 Share on other sites More sharing options...
daebat Posted October 15, 2009 Author Share Posted October 15, 2009 Thanks! So if I use $_FILES instead of POST will it still store the file name to reference in the database? Link to comment https://forums.phpfreaks.com/topic/177778-image-upload/#findComment-937433 Share on other sites More sharing options...
StefanRSA Posted October 15, 2009 Share Posted October 15, 2009 You can get the file name from $_FILES["img"]["tmp_name"] Link to comment https://forums.phpfreaks.com/topic/177778-image-upload/#findComment-937437 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.