harkly Posted April 14, 2010 Share Posted April 14, 2010 I have a site that allows users to add, delete images. There are 3 options 1. Make no changes 2. Add/change photo 3. Delete photo I have all of these working on there own but now need to combine them and cannot get that to work. Here is my English version If no file or checkbox is selected do nothing, if file is selected update db, if checkbox is selected delete from db. Here is my form <form enctype='multipart/form-data' action='testDelete.php' method='POST'> <input type='hidden' name='MAX_FILE_SIZE' value='100000' /> <div id='imageTop'>Image 1</div> <div id='imageBottom'> <span class='image'>"; if (empty($photo_1)) { echo " <img src='uploads/noPhoto.jpg' width='71' height='71' class='zip'> "; } else { echo "<a href='uploads/$photo_1' ><img src='uploads/$photo_1' width='71' height='71' class='zip'></a> "; } echo " </span> <span class='action'> <input type='file' name='photo_1' class='zip'><br><br> <input type='checkbox' name='delete_1'>Select to Delete image </span> </div> </form> Here is the update codes for each To add/change photo if ($photo_1 != 'null') { $extension = strrchr($_FILES['photo_1']['name'],'.'); $extension = strtolower($extension); $photoNumber="_1"; $finalName="$userID$photoNumber"; $save_path = "uploads/"; $target_path = $save_path . basename( $_FILES['photo_1']['name']); $NewPhotoName = $finalName; $withExt1 = $NewPhotoName . $extension; $filename = $save_path . $NewPhotoName . $extension; if(move_uploaded_file($_FILES['photo_1']['tmp_name'], $filename)) { $query = "UPDATE photos SET photo_1='$withExt1' WHERE userID='$userID'"; $result = mysql_query($query) or die(mysql_error()); } else{ echo "No file selected <br>"; } } if ($delete_1 != 'null') { $query = "UPDATE photos SET photo_1='' WHERE userID='$userID'"; result = mysql_query($query) or die(mysql_error()); } I know this is probably not the best way to do it but I am very new at this and taking baby steps. If someone could point me in the right direction I would appreciate that! Also, what is the proper syntex for this? This doesn't seem right to me. if ($photo_1 != 'null') Link to comment https://forums.phpfreaks.com/topic/198550-adddeleting-to-db-not-working/ Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 <span class='image'>"; if (empty($photo_1)) { echo " <img src='uploads/noPhoto.jpg' width='71' height='71' class='zip'> "; } else { echo "<a href='uploads/$photo_1' ><img src='uploads/$photo_1' width='71' height='71' class='zip'></a> "; } echo " </span> ^ Woah... what is all that? A quote & semi-colon in HTML + some PHP code without PHP tags? Link to comment https://forums.phpfreaks.com/topic/198550-adddeleting-to-db-not-working/#findComment-1041898 Share on other sites More sharing options...
harkly Posted April 14, 2010 Author Share Posted April 14, 2010 I didn't put the full php in there, didn't think it was needed. <?php $userID='test'; include('library/login.php'); login(); mysql_select_db('test'); $result = mysql_query("SELECT * FROM photos WHERE userID LIKE '$userID'"); while ($r=mysql_fetch_array($result)) { $photo_1=$r['photo_1']; $photo_2=$r['photo_2']; $photo_3=$r['photo_3']; $photo_4=$r['photo_4']; $photo_5=$r['photo_5']; echo " <form enctype='multipart/form-data' action='testDelete.php' method='POST'> <input type='hidden' name='MAX_FILE_SIZE' value='500000' /> <div id='imageTop'>Image #1</div> <div id='imageBottom'> <span class='image'>"; <form enctype='multipart/form-data' action='testDelete.php' method='POST'> <input type='hidden' name='MAX_FILE_SIZE' value='100000' /> <div id='imageTop'>Image 1</div> <div id='imageBottom'> <span class='image'>"; if (empty($photo_1)) { echo " <img src='uploads/noPhoto.jpg' width='71' height='71' class='zip'> "; } else { echo "<a href='uploads/$photo_1' ><img src='uploads/$photo_1' width='71' height='71' class='zip'></a> "; } echo " </span> <span class='action'> <input type='file' name='photo_1' class='zip'><br><br> <input type='checkbox' name='delete_1'>Select to Delete image </span> </div> </form> "; ?> Link to comment https://forums.phpfreaks.com/topic/198550-adddeleting-to-db-not-working/#findComment-1041902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.