smproph Posted January 9, 2011 Share Posted January 9, 2011 I have a search that the user can use and pulls up the records from the database. I made it to where you can click on an image and it will let you edit that record, problem is, it won't let me edit the 1st record that is populated, the rest work fine. Can you find what I am doing wrong? while ($row = mysql_fetch_array($result)) { $rid=$row['timeslip_id']; $rint=$row['Initials']; $rident=$row['Identifier']; $rtype=$row['Type']; $rterms=$row['Terms']; $rmemo=$row['Memo']; $rdate=$row['Date']; $rcost=$row['Cost']; ?> <tr> <td valign="top"></td> <td valign="top"> <form action="editslip.php" name="<?=$rid?>" method="post"> <input type="hidden" name="edata" value="<?=$rid?>"> </form> <a href="#" onclick="document['<?=$rid?>'].submit()"><img src="images/pencil.png" height="24px" width="24px"/></a></td> <td valign="top" align="left"><?=$rint?></td> <td valign="top" align="left"><?=$rident?></td> <td valign="top" align="left"><?=$rtype?></td> <td valign="top" align="left"><?=$rterms?></td> <td valign="top" align="left"> <?php $convdate = date('m/d/Y', strtotime($rdate));?> <?=$convdate?></td> <td valign="top"><?=$rcost?></td> <td valign="top"> <?php echo substr($rmemo,0,100);?></td> <td align="center"><input type="checkbox" name="del[]" id="del" value="<?=$row['timeslip_id']?>"></td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/223826-php-only-lets-me-edit-1st-line-from-query/ Share on other sites More sharing options...
smproph Posted January 9, 2011 Author Share Posted January 9, 2011 Okay so I used firebug and noticed that my first record looks like this <td> <input type="hidden" value "13" name="edata"> <a onclick="document['13'].submit()" href="#"> <img width="24px" height="24px" src="images/pencil.png"> </a> And the second record is returning... <td> <form method="post" name="14" action="edittask.php"> <input type="hidden" value "14" name="edata"> </form> <a onclick="document['14'].submit()" href="#"> <img width="24px" height="24px" src="images/pencil.png"> </a> Why is my php writing the form for the 2nd record but not the 1st one? Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/223826-php-only-lets-me-edit-1st-line-from-query/#findComment-1156908 Share on other sites More sharing options...
Pikachu2000 Posted January 9, 2011 Share Posted January 9, 2011 You're going to need to post from the query string to where the code above starts. Quote Link to comment https://forums.phpfreaks.com/topic/223826-php-only-lets-me-edit-1st-line-from-query/#findComment-1156911 Share on other sites More sharing options...
smproph Posted January 9, 2011 Author Share Posted January 9, 2011 That's my code for my Search Results page <?php mysql_connect ("***", "***","***") or die (mysql_error()); mysql_select_db ("***"); $qry_str="SELECT * FROM tasks WHERE 1 "; if($_POST['Owner']) { $Owner=$_POST['Owner']; $qry_str.="and Owner='$Owner' "; } if($_POST['Identifier']) { $Identifier=$_POST['Identifier']; $qry_str.="and Identifier LIKE '%$Identifier%' "; } if($_POST['Staff']) { $Staff=$_POST['Staff']; $qry_str.="and Staff='$Staff' "; } if($_POST['Date']) { $Date=$_POST['Date']; $qry_str.="and Date LIKE '%$Date%' "; } if($_POST['Priority']) { $Priority=$_POST['Priority']; $qry_str.="and Priority='$Priority' "; } if($_POST['Status']) { $Status=$_POST['Status']; $qry_str.="and Status LIKE '%$Status%' "; } if($_POST['Description']) { $Description=$_POST['Description']; $qry_str.="and Description LIKE '%$Description%' "; } if($_POST['start1']) { $start1=$_POST['start1']; $start2=$_POST['start2']; $start=date('Y-m-d', strtotime($start1)); $end=date('Y-m-d', strtotime($start2)); $qry_str.="and start >= '$start' and start <= '$end' "; } if($_POST['end1']) { $end1=$_POST['end1']; $end2=$_POST['end2']; $start=date('Y-m-d', strtotime($end1)); $end=date('Y-m-d', strtotime($end2)); $qry_str.="and due >= '$start' and due <= '$end' "; } ?> <form action="deletetask.php" method="POST"> <table class="example table-autostripe table-rowshade-alternate"> <thead> <tr><th width="1px"></th> <th style="text-align:left;" width="40px">Edit</th> <th width="70px" class="table-sortable:default" align="left">Initials</th> <th width="70px" class="table-sortable:default" align="left">Staff</th> <th width="150px" class="table-sortable:default" align="left">Identifier</th> <th width="100px" class="table-sortable:date" align="left">Due</th> <th width="35px" class="table-sortable:numeric" align="left">Pri</th> <th width="140px" class="table-sortable:default" align="left">Status</th> <th width="350px" class="table-sortable:default" align="left">Description</th> </tr> </thead> <tbody> <? $result=mysql_query($qry_str); $count=mysql_num_rows($result); while ($row = mysql_fetch_array($result)){ $rid=$row['task_id']; $rowner=$row['owner']; $rstaff=$row['staff']; $rident=$row['identifier']; $rdate=$row['due']; $rpriority=$row['priority']; $rstatus=$row['status']; $rdesc=$row['description']; ?> <tr> <td valign="top"></td> <td valign="top"> <form action="edittask.php" name="<?=$rid?>" method="post"> <input type="hidden" name="edata" value="<?=$rid?>"> </form> <a href="#" onclick="document['<?=$rid?>'].submit()"><img src="images/pencil.png" height="24px" width="24px"/></a></td> <td valign="top" align="left"><?=$rowner?></td> <td valign="top" align="left"><?=$rstaff?></td> <td valign="top" align="left"><?=$rident?></td> <td valign="top" align="left"> <?php $convdate = date('m/d/Y', strtotime($rdate));?> <?=$convdate?></td> <td valign="top" align="left"><?=$rpriority?></td> <td valign="top" align="left"><?=$rstatus?></td> <td valign="top" align="left"><?=$rdesc?></td> <td align="center"><input type="checkbox" name="del[]" id="del" value="<?=$row['task_id']?>"></td> </tr> <? } ?> </tbody> <tbody> <tr> <td colspan="10" align="center"><input type="submit" name="justdel" value="Delete" id="justdel"></td></tr></td> </tr> </tbody> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/223826-php-only-lets-me-edit-1st-line-from-query/#findComment-1156916 Share on other sites More sharing options...
smproph Posted January 9, 2011 Author Share Posted January 9, 2011 Okay so after using Firefox Error Console, it is saying that document[13] is undefined. Not sure if that helps. Quote Link to comment https://forums.phpfreaks.com/topic/223826-php-only-lets-me-edit-1st-line-from-query/#findComment-1156926 Share on other sites More sharing options...
PFMaBiSmAd Posted January 9, 2011 Share Posted January 9, 2011 It's not working because your first form on the page - <form action="deletetask.php" method="POST"> does not have a closing </form> tag, resulting in invalid HTML. Quote Link to comment https://forums.phpfreaks.com/topic/223826-php-only-lets-me-edit-1st-line-from-query/#findComment-1156928 Share on other sites More sharing options...
smproph Posted January 9, 2011 Author Share Posted January 9, 2011 The closing form was at the very end. Guess you can't really have a form inside a form. How would I get around this because I need the two input values to be apart of a form separate from my Edit form. The while loop is what is throwing me off because some of the form i.e. the check boxes to select which ones you want to delete and in the loop and the actual DELETE submit button is outside the loop. <form action="edittask.php" name="<?=$rid?>" method="post"> <input type="hidden" name="edata" value="<?=$rid?>"> </form> <a href="#" onclick="document['<?=$rid?>'].submit()"><img src="images/pencil.png" height="24px" width="24px"/></a></td> <td valign="top" align="left"><?=$rowner?></td> <td valign="top" align="left"><?=$rstaff?></td> <td valign="top" align="left"><?=$rident?></td> <td valign="top" align="left"> <?php $convdate = date('m/d/Y', strtotime($rdate));?> <?=$convdate?></td> <td valign="top" align="left"><?=$rpriority?></td> <td valign="top" align="left"><?=$rstatus?></td> <td valign="top" align="left"><?=$rdesc?></td> <td align="center">[color=yellow]<input type="checkbox" name="del[]" id="del" value="<?=$row['task_id']?>">[/color]</td> </tr> <? } ?> </tbody> <tbody> <tr> <td colspan="10" align="center">[color=yellow]<input type="submit" name="justdel" value="Delete" id="justdel">[/color]</td></tr></td> Quote Link to comment https://forums.phpfreaks.com/topic/223826-php-only-lets-me-edit-1st-line-from-query/#findComment-1156933 Share on other sites More sharing options...
smproph Posted January 9, 2011 Author Share Posted January 9, 2011 Ok couldn't figure out how to edit my last post. Here is what I need to accomplish. I have two forms, Edit and Delete. My while loop is creating an Edit form for every record. Problem is I am also putting a checkbox input inside the WHILE loop which is not apart of the Edit Form. The checkboxes are apart of the Delete form, which the submit button is outside the WHILE loop. I know you can't have a form inside a form. Any ideas on how I can get around this problem? My overall goal is that I am trying to be able to Edit and Delete my records. Quote Link to comment https://forums.phpfreaks.com/topic/223826-php-only-lets-me-edit-1st-line-from-query/#findComment-1156945 Share on other sites More sharing options...
fesan Posted January 9, 2011 Share Posted January 9, 2011 Use the same form to do both delete and edit. Make statement that checks for delete check box and delete after that. If(isset($delete) && !empty($delete)){ //DELETE CODE } Quote Link to comment https://forums.phpfreaks.com/topic/223826-php-only-lets-me-edit-1st-line-from-query/#findComment-1156971 Share on other sites More sharing options...
PFMaBiSmAd Posted January 9, 2011 Share Posted January 9, 2011 There's no point in having a form just to select the edit function. You are not using it for any user entered input (forms are for getting some kind of user determined input values.) Just make the <a href=""></a> a link to your edittask.php page with a GET parameter on the end of the url that indicates which $rid you want to edit. Quote Link to comment https://forums.phpfreaks.com/topic/223826-php-only-lets-me-edit-1st-line-from-query/#findComment-1157001 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.