Hello everybody, am working on a small php project and in some pages i have dynamic table to read date from another table in MySql database and i added into same table a javascript code for inserting new row. the fields in the table is:
Value (input type="text")
time (generated)
date (generated)
my issue here is how i can insert this new row to database table with this fields
INDEX (auto increment)
Value
time
date
pat_id (foreign key)
this is javascript function i use:
<script type="text/javascript">
function addRow(patInfo) {
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var table = document.getElementById(patInfo);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "text";
element1.size = "3";
element1.name = "value";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
var element2 = document.createElement("span");
element2.name = "time";
element2.innerHTML = hours + ":" + minutes;
cell2.appendChild(element2);
var cell3 = row.insertCell(2);
var element3 = document.createElement("span");
element3.name = "date";
element3.innerHTML = day + "-" + month + "-" + year
cell3.appendChild(element3);
}
</script>
and this is the table:
<?php
$InsertTemp = $_SERVER['PHP_SELF'];
mysql_query("INSERT INTO ptemperature (INDEX, value, time, date, pat_id)
VALUES ('','$_GET[value]', '$_GET[time]', '$_GET[date]', 'a')");
?>
<form action="<?php echo $InsertTemp ?>" method="get">
<table id="patInfo" style="width:auto; display:inline; float:left;" cellspacing="0">
<tr><th colspan="2">Temperature ºC</th><th><img onClick="addRow('patInfo')" width="20px" height="20px" src="images/add_32.png"/></th></tr>
<tr><th style="border-top:1px solid #e0e0e0;">Value</th><th style="border-top:1px solid #e0e0e0;">Time</th><th style="border-top:1px solid #e0e0e0;">Date</th></tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset2['value']; ?></td>
<td><?php echo $row_Recordset2['time']; ?></td>
<td><?php $sqldate=date('d-m-Y',strtotime($row_Recordset2['date']));
echo $sqldate; ?></td>
</tr>
<?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>
</table>
<input type="submit" value="submit" />
</form>
pleeease i need very quick help...