Jump to content

PHP only lets me edit 1st line from query


smproph

Recommended Posts

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>
  

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.