i tried to mimic the code of a tutorial for a live updatable table....dat is connected to the MYSQL server ....
i copied it and edited it a bit...but its not working...
i was not able to understand the code so dont knw where the problem is

here is the website http://www.9lessons.info/2011/03/live-table-edit-with-jquery-and-ajax.html


and here is my code:


my table columns in MYSQL:
TAble name :: request_made
columns::
id
eno
date
out_date
out_time
in_date
in_time
status

the webpage:

<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(".edit_tr").click(function()
{
var ID=$(this).attr('id');

$("#eno_"+ID).hide();
$("#date_"+ID).hide();
$("#out_date_"+ID).hide();
$("#out_time_"+ID).hide();
$("#in_date_"+ID).hide();
$("#in_time_"+ID).hide();
$("#status_"+ID).hide();



$("#eno_input_"+ID).show();
$("#date_input_"+ID).show();
$("#out_date_input_"+ID).show();
$("#out_time_input_"+ID).show();
$("#in_date_input_"+ID).show();
$("#in_time_input_"+ID).show();
$("#status_input_"+ID).show();





}).change(function()
{
var ID=$(this).attr('id');
var eno=$("#eno_input_"+ID).val();
var date=$("#date_input_"+ID).val();
var out_date=$("#out_date_input_"+ID).val();
var out_time=$("#out_time_input_"+ID).val();
var in_date=$("#in_date_input_"+ID).val();
var in_time=$("#in_time_input_"+ID).val();
var status=$("#status_input_"+ID).val();


var dataString = 'eno='+ eno +'&date='+date+'&id='+id+'&out_date='+out_date+'&out_time='+ out_time +'&in_date='+ in_date +'&in_time='+ in_time 

+'&status='+ status;


if(eno.length>0)
{

$.ajax({
type: "POST",
url: "table_edit_ajax.php",
data: dataString,
cache: false,
success: function(html)
{
$("#eno_"+ID).html(eno);
$("#date_"+ID).html(date);
$("#out_date_"+ID).html(out_date);
$("#out_time_"+ID).html(out_time);
$("#in_date_"+ID).html(out_date);
$("#in_time_"+ID).html(out_time);
$("#status_"+ID).html(status);
}
});
}
else
{
alert('Enter something.');
}

});

// Edit input box click action
$(".editbox").mouseup(function() 
{
return false
});

// Outside click action
$(document).mouseup(function()
{
$(".editbox").hide();
$(".text").show();
});

});
</script>

<table>
<tr><th>eno</th><th>date</th><th>out_date</th><th>out_time</th><th>in_date</th><th>in_time</th><th>status</th>
</tr>
<?php
include('conn.php');
$sql=mysql_query("select * from request_made");
while($row=mysql_fetch_array($sql))
{
$id=$row['id'];
$eno=$row['eno'];
$date=$row['date'];
$out_date=$row['out_date'];
$out_time=$row['out_time'];
$in_date=$row['in_date'];
$in_time=$row['in_time'];
$status=$row['status'];


?>


<tr id="<?php echo $id; ?>" class="edit_tr">

<td class="edit_td">
<span id="eno_<?php echo $id; ?>" class="text"><?php echo $eno; ?></span>
<input type="text" value="<?php echo $eno; ?>" class="editbox" id="eno_input_<?php echo $id; ?>" /&gt;
</td>

<td class="edit_td">
<span id="date_<?php echo $id; ?>" class="text"><?php echo $date; ?></span> 
<input type="text" value="<?php echo $date; ?>" class="editbox" id="date_input_<?php echo $id; ?>"/>
</td>

<td class="edit_td">
<span id="out_date_<?php echo $id; ?>" class="text"><?php echo $out_date; ?></span>
<input type="text" value="<?php echo $out_date; ?>" class="editbox" id="out_date_input_<?php echo $id; ?>" /&gt;
</td>

<td class="edit_td">
<span id="out_time_<?php echo $id; ?>" class="text"><?php echo $out_time; ?></span>
<input type="text" value="<?php echo $out_time; ?>" class="editbox" id="out_time_input_<?php echo $id; ?>" /&gt;
</td>

<td class="edit_td">
<span id="in_date_<?php echo $id; ?>" class="text"><?php echo $in_date; ?></span>
<input type="text" value="<?php echo $in_date; ?>" class="editbox" id="in_date_input_<?php echo $id; ?>" /&gt;
</td>

<td class="edit_td">
<span id="in_time_<?php echo $id; ?>" class="text"><?php echo $in_time; ?></span>
<input type="text" value="<?php echo $in_time; ?>" class="editbox" id="in_time_input_<?php echo $id; ?>" /&gt;
</td>


<td class="edit_td">
<span id="status_<?php echo $id; ?>" class="text"><?php echo $status; ?></span>
<input type="text" value="<?php echo $status; ?>" class="editbox" id="status_input_<?php echo $id; ?>" /&gt;
</td>


</tr>
<?php
}
?>
</table>

and here is the php connectivity file:

<?php
include("conn.php");
if($_POST['id'])
{
$id=mysql_escape_String($_POST['id']);
$eno=mysql_escape_String($_POST['eno']);
$date=mysql_escape_String($_POST['date']);
$out_date=mysql_escape_String($_POST['out_date']);
$out_time=mysql_escape_String($_POST['out_time']);
$in_date=mysql_escape_String($_POST['in_date']);
$in_time=mysql_escape_String($_POST['in_time']);
$status=mysql_escape_String($_POST['status']);

$sql = "update request_made set eno='$eno',date='$date',out_date='$out_date',out_time='$out_time',in_date='$in_date',in_time='$in_time',status='$status' 
where id='$id'";
mysql_query($sql);
}

?>

The problem is that the changes that i try to make are not affecting the database

Thanks in advance

Line 20 is not valid PHP, that could break it.

sry...forgot to cut that shit out....
but no....thats still not working....
can you try the code urself....
i cant figure out what the problem is

finally did it.....
small error... :D
forgot to make ID in capitals....damm :P

@himanshu.1691 what do you mean by ID? the one in the javascript or the ones in the textfields? or perhaps the span? Kindly state the details of your resolve coz am having the same issue. Thanks.

also, I'm having trouble with the date function. It appears not saving. Do you have any idea what to do?

Great now I know how to live edit table :D
@Angellore_1 did you check connection to db in your php file ?

I got immence idea about PHP now.. thnx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.