I am currently having issues with save the table data in data.csv file. Using this javascript I am getting the value from table and show it in alert box. But I want to store this variable data in adata.csv file. I have passed the hidden field value into this page. Please edit my code. Because this is my first PHP code.
Here is my code:
<html>
<head>
<script>
function GetCellValues()
{
var str = '';
var rows = document.getElementsByTagName('tr');
var table=document.getElementById("project");
for (var i=0;i<table.rows[0].cells.length;i++)>
{
if (i > 2 )
{
str = str + table.rows[0].cells[3].innerHTML.replace(", ");
}
else
{
str = str + (table.rows[0].cells[i].innerHTML) + ', ' ;
}
}
for (var c = 1 ; c < rows.length ; c++)
{
str += '\n' + "0" + c + ', ';
var row = rows[c];
var inputs = row.getElementsByTagName('input');
for (var k = 0 ; k < inputs.length ; k++)
if (k > 1)
{
str += inputs[k].value.replace(", ");
}
else
{
str += inputs[k].value + ', ';
}
}
document.getElementById('hiden').value = str;
alert(document.getElementById('hiden').value);
}
Here I have the problem, I am not able to save the table data into the file.
function saved()
{
$handle = fopen("data.csv", "w");
$hiden = $_REQUEST["hiden"];
fwrite($handle,$hiden);
}
?>
</script>
</head>
I have made the buttons in the following way:
<body>
<form>
* * * PROJECTS * * *
<input type = "hidden" id = "hiden" name = "hiden" value = "">
<input type = "button" name = "submit" önclick = "GetCellValues()" Value = "SAVE">
<input type = "button" name = "submit" önclick = "document.write('');" Value = "submit">
</form>
Here I stored the data from .csv file and display it in table:
$handle = fopen("data.csv", "w");
$hide = $_REQUEST['hide'];
fwrite($handle,$hide);
$file = file('data.csv');
$lines = count($file);
echo'
style = "width: 60%; margin-removed auto; margin-removed auto; border-color: brown; background-color:gray;">';
echo'';
for ($i=1; $i<$lines; $i++)
{
$part = explode(',', $file[$i]);
echo'
';
}
echo'
Sl.No. | Project Name | ChangeDate | Changed By |
'.$part[0].' | <input type="text" value='.$part[1].'> | <input type="text" value='.$part[2].'> | <input type="text" value='.$part[3].'> |
';
?>
</body>
</html>