arya2k10 Posted November 28, 2010 Share Posted November 28, 2010 Friends I am new to php and i have to submit my coursework in php by 3rd dec, I stuck at one place where i have to upload multiple photo and one can see all the photo he has uploaded and can edit or delete that photo so i have done uploading now i am showing those pics in table by running loop and generating tr and td but now i have two buttons with each row edit and delete now when i clicked on one delete or edit that pic should be delete or give text box to edit description of pic, Please help me how to do that....... Quote Link to comment Share on other sites More sharing options...
litebearer Posted November 28, 2010 Share Posted November 28, 2010 Someone may be able to better help if we see your existing code Quote Link to comment Share on other sites More sharing options...
arya2k10 Posted November 28, 2010 Author Share Posted November 28, 2010 while($i<$num) { echo "<tr>"; $myimage= mysql_result($result,$i,"imagename"); $photoID= mysql_result($result,$i,"PhotoID"); $des= mysql_result($result,$i,"des"); if ( preg_match('/(\.gif|\.GIF|\.PNG|\.png|\.JPG|\.jpg|\.JPEG|\.jpeg)$/',$myimage)) { $filename = 'Photos/' . mysql_result($result,$i,"imagename"); $imagesize = getImageSize($filename); echo "<td><img id=\"myimg\" src=\"$filename\" alt=\"$myimage\"/><br/>$des<br/>"; echo "<input type=\"submit\" name='SUBMIT' value=\"Edit\"><input type=\"submit\" name='SUBMIT' value=\"Delete\"></td>"; } } Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 28, 2010 Share Posted November 28, 2010 One way I can think of is to make the submit buttons an array. Then in the processing script, if you use: $id = array_flip($_POST['submit']) the value you need will reside in: $id['submit']. One problem I can see happening is that the behavior may be unpredictable if the form is submitted with the enter key rather than a submit button. echo "<input type=\"submit\" name=\"submit[$photoID]\" value=\"Submit\"><br>"; Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 28, 2010 Share Posted November 28, 2010 Ah, hang on a few minutes, I need to rework that to take into account that there's more than one possible action for each photo . . . Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 28, 2010 Share Posted November 28, 2010 Paste this into a file so you can see how it works, and it should be pretty obvious how to implement it. <?php // processing foreach( $_POST['submit'] as $k => $v ) { $action = $v; $id = $k; } echo "The file with id# $id will undergo this action: $action"; // Added a range of id's just to test with . . . $id = range(100, 110); echo "<form method=\"post\" action=\"\">"; foreach( $is as $photoID ) { echo "$photoID <input type=\"submit\" name=\"submit[$photoID]\" value=\"Edit\"> <input type=\"submit\" name=\"submit[$photoID]\" value=\"Delete\"><br>"; } echo "</form>"; ?> Added . . . tags. Quote Link to comment Share on other sites More sharing options...
arya2k10 Posted November 28, 2010 Author Share Posted November 28, 2010 Dear Friend Thanks for reply, Its working but not fully, I have checked its providing proper ID but not action action is remain same whether you click on any button. if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_POST['SUBMIT']=='Search') { $searchtxt= $_REQUEST['search']; header("location:search.php?search=$searchtxt&page=0"); exit; } if ($_POST['SUBMIT']=='Edit Image') { $myimage="getImage.php?ID=$ID"; $html1="<img id='myimg' src=$myimage alt='Welcome'/><br/><input size='2' type='file' name='myimage' id='myimage'/><div id='lblerr'>" . $err . "</div> <input type='SUBMIT' value='Update Image' name='SUBMIT'/>"; } } i have got multiple submit buttons like search and edit image edit profile etc and i am getting those back on post back as per above code, I want to get this also as per above so that i can perform activity on that like delete that pic is click on delete and provide textarea if edit is clicked t edit description of pic Regards Parveen Kumar Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 28, 2010 Share Posted November 28, 2010 The logic of that code isn't even close to what I posted, so it isn't any surprise it doesn't work. Pay attention to how I have each button named as an array using $photoID, and that the value= attribute is the action that will be performed. Quote Link to comment Share on other sites More sharing options...
arya2k10 Posted November 28, 2010 Author Share Posted November 28, 2010 Thanks its doen and now i can delete pic, edit description and update description of any from the table, thank you very much...... Sincerely Parveen Kumar 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.