Hi
I have a PHP page to update and delete row data retrieved from a MySQL database & when i click on the update link(at the end column) beside the particular row in the browser,it should open up a form with only the particular row showing input boxes for each field and a edit button at the last column. And when I will edit the input boxes of the particular row on the browser and then click on 'submit' (here the edit button), it will fetch & show only my updated row from the database(i.e. not all the rows from the table).
Here the table is named as `activities` table with the fields as `id`,`sports_category`,`year` and `winner`.
But my code is not showing the desired row,instead it is retrieving all the rows from the table.
Here is my last tried code where none of the data from the table is showing!!
Here is the code -
In the abode code I have used a 'upd' variable which is being passed through a update link in another page.These part of the code starting fromPHP Code:<?php
$c=1;
$sel2="select * from `activities` where `id`='$_GET[upd]' ";
$res2=mysql_query($sel2);
while($row=mysql_fetch_array($res2))
{
if($_GET['upd']=="$row[id]")
{
echo "<TABLE border=0 height=200 width=400>
<THEAD>
<TR>
<TH>SERIAL NO.</TH>
<TH>SPORT NAME</TH>
<TH>YEAR</TH>
<TH>WINNER</TH>
<TH COLSPAN=2 ALIGN=CENTER>ACTION</TH>
</TR>
</THEAD>
<TBODY>
<FORM METHOD='POST' ACTION='' name='f2'>
<tr>
<td class=bb >$c</td>
<td class=bb ><INPUT TYPE='text' value='$row[sports_category]' name='spocat'></td>
<td class=bb ><INPUT TYPE='text' value='$row[year]' name='uyr'></td>
<td class=bb ><INPUT TYPE='text' value='$row[winner]' name='win'></td>
<INPUT TYPE='hidden' NAME='hd' value='$row[id]'>
<td colspan=2 align=center class=bb><INPUT TYPE='submit' name='ed' value='Edit' class=bb><td>
</tr></FORM>
</TBODY>
</TABLE>";
}
}
if($_GET['page']=="show")
{
echo "<TABLE border=0 height=200 width=400>
<THEAD>
<TR>
<TH>SERIAL NO.</TH>
<TH>SPORT NAME</TH>
<TH>YEAR</TH>
<TH>WINNER</TH>
</TR>
</THEAD>
<TBODY>";
$u=$_GET['ed'];
$sel3="select * from `kris`.`activities` where id='$h' ";
$res3=mysql_query($sel3);
while($row3=mysql_fetch_array($res3))
{
echo "<tr>
<td class=bb>$row3[id]</td>
<td class=bb>$row3[sports_category]</td>
<td class=bb>$row3[year]</td>
<td class=bb>$row3[winner]</td>
</tr>";
$c++;
}
}
?>toPHP Code:if($_GET['upd']=="$row[id]")
is working fine. But then when I click on the "Edit" button ,the value is getting updated in the database but the desired row is not showing on the browser!!PHP Code:<td colspan=2 align=center class=bb><INPUT TYPE='submit' name='ed' value='Edit' class=bb><td>
</tr></FORM>
</TBODY>
</TABLE>";
Please tell me what tweak in the MySQL code is to be done in the $_GET[show] part of the above code??
And here is the php code for the edit part-(it should be at the start before the above code)
Will be greatly obliged for any genuine help.PHP Code:if($_POST['ed']=="Edit")
{
$spt=$_POST['spocat'];
$yar=$_POST['uyr'];
$wnr=$_POST['win'];
$h=$_POST['hd'];
$a="UPDATE `k`.`activities` SET `sports_category` = '$spt', `year` = '$yar', `winner` = '$wnr' WHERE `activities`.`id` ='$h' ";
mysql_query($a);
header("location:upd_a.php?page=show&msg=updated successfully");
}
![]()



Reply With Quote
Bookmarks