can anyone help me with this code. I m trying to view and edit on same table...

  • Thread starter Thread starter Shahbaz singh
  • Start date Start date
S

Shahbaz singh

Guest
...in php and javascript? this is code taken from net. This has a prob when i click two edit buttons it changes to update but i waant only single row update feature. PLZ help
here is the code

<?php
mysql_connect("localhost","root","tree") or die ("can not connect to database because".mysql_error());
mysql_select_db("jaggi");

if(isset($_POST['sbmt']))
{
$a=$_POST['id'];
$b=$_POST['uname'];
$c=$_POST['pass'];
$d=$_POST['fname'];
$slct=mysql_query("update signup set uname='$b',pas='$c',fname='$d' where id='$a' ") or die(mysql_error());
if ($slct) {
echo "Update succeed!<br>";
}
}
?>
<script>
function vsb(id, uname, pass, fname)
{
divid= id;
document.getElementById(divid).innerHTML+= '<input type=hidden name=id value="'+id+'">';
divid= id+uname;
document.getElementById(divid).innerHTML= '<input type=text name=uname value="'+uname+'" size=15>';
divid= id+pass;
document.getElementById(divid).innerHTML= '<input type=text name=pass value="'+pass+'" size=15>';
divid= id+fname;
document.getElementById(divid).innerHTML= '<input type=text name=fname value="'+fname+'" size=15>';
divid= id+"edt";
document.getElementById(divid).innerHTML= '<input type=submit name=sbmt value="Update">';
}
</script>
<form action='' method=post>
<table border='1' cellspacing=3 cellpadding=3>
<?
$a=mysql_query("select * from signup");
while ($b=mysql_fetch_array($a))
{
?>
<tr>
<td><div id='<?php echo $b[id]; ?>'><? echo $b[id];?></div></td>
<td><div id='<?php echo $b[id].$b[uname]; ?>'><? echo $b[uname];?></div></td>
<td><div id='<?php echo $b[id].$b[pas]; ?>'><? echo $b[pas];?></div></td>
<td><div id='<?php echo $b[id].$b[fname]; ?>'><? echo $b[fname];?></div></td>
<td><div id='<?php echo $b[id]."edt"; ?>'><input type="button" name='edt' value="Edit" onclick="vsb(<? echo "'$b[id]', '$b[uname]', '$b[pas]', '$b[fname]'"; ?>);

return false" /></div></td>
</tr>

<? } ?>
</table>
</form>
 
Back
Top