all i want is to make the user able to edit when he clicks on the value and on blur the value get edited
like it works here in the forum ,when i try to edit,it edited on the same page !! and i got this code,it works fine if i changed the update statement to insert
but in updating , it doesnt update anything and when i echoed the statement it gave me that:
update porto set porto_name = 'Websss' where porto_ID=''
and this is the code
<head>
<script type="text/javascript">
var contents = '';
function toggle(porto_ID)
{
if (document.getElementById('r_'+porto_ID).style.display == 'none')
{
if (document.forms['form_'+porto_ID].porto_name.value != contents)
{
// If the contents of the box have changed, submit the form.
document.forms['form_'+porto_ID].submit();
}
document.getElementById('w_'+porto_ID).style.display = 'none';
document.getElementById('r_'+porto_ID).style.display = 'inline';
}else
{
document.getElementById('w_'+porto_ID).style.display = 'inline';
document.forms['form_'+porto_ID].porto_name.focus();
contents = document.forms['form_'+porto_ID].porto_name.value;
document.getElementById('r_'+porto_ID).style.display = 'none';
}
}
</script>
</head>
<?php
$conn=mysql_connect("localhost","root","123456");
$db=mysql_select_db("epic");
$Recordset1=mysql_query("select * from porto");
?>
<table >
<tr>
<th>Name</th>
</tr>
<?php do{ ?>
<tr>
<td>
<div id="r_<?php echo $row_Recordset1['porto_ID']; ?>" onclick="toggle('<?php echo $row_Recordset1['porto_ID']; ?>')">
<?php echo $row_Recordset1['porto_name']; ?>
</div>
<div id="w_<?php echo $row_Recordset1['porto_ID']; ?>" style="display: none;">
<form id="form_<?php echo $row_Recordset1['porto_ID']; ?>" method=post
action=<?php echo $_SERVER['PHP_SELF']; ?> >
<input onblur="toggle('<?php echo $row_Recordset1['porto_ID']; ?>')"
type=text
name="porto_name" value='<?php echo $row_Recordset1['porto_name']; ?>' />
</form>
</div>
</td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<?php
if($porto_name){
$query_line = "update porto set porto_name = '". $porto_name ."' where porto_ID='".$porto_ID."'";
$sql = mysql_query($query_line);
if(@$sql) echo mysql_error() . $query_line;
}