Reputation: 41
I retrieve the data from CSV file and store it in table using PHP. In this table I am using textboxes within td where I can edit the table data. Now I want to store this edited data in the CSV file, but I am not able to store this edited data from this table to CSV file.
Here is my code:
<html>
<head>
</head>
<body>
<div>
<br>
<h1 style="text-align: center">* * * PROJECTS * * *</h1>
<br>
<input type = "hidden" id = "hide" name = "hide" value = "">
<input type = "button" name = "submit" onclick = "document.write('<?php echoAlert() ?>');" Value = "SAVE">
<br>
</div>
<?php
function echoAlert()
{
// What do I have to write here to store the data in CSV file?
}
?>
<?php
$handle = fopen("data.csv", "w"); // this is my .csv file.
$hide = $_REQUEST['hide']; // here I will retrieve the data from data.csv file
fwrite($handle,$hide); // Here I will write the data from file to table
$file = file('data.csv');
$lines = count($file);
This is my table, here I write the file.
echo'<table id = "projest" border = "1" cellpadding="2" cellspacing="0"
style = "width: 60%; margin-left: auto; margin-right: auto; border-color: brown; background-color:gray;">';
for ($i=1; $i<$lines; $i++)
{
$part = explode(',', $file[$i]);
echo'<tr>
<td align= "center" width="5%">'.$part[0].'</td>
<td align= "center" width="25%"><input type="text" value='.$part[1].'></td>
<td align= "center" width="25%"><input type="text" value='.$part[2].'></td>
<td align= "center" width="25%"><input type="text" value='.$part[3].'></td>
</tr>';
}
echo'</table>';
?>
Here I can edit the data.... The problem is I want to store this edited data in this same csv file. But not able to store it.
Please give me some code to store this table data in a CSV file.
</body>
</html>
Upvotes: 1
Views: 876
Reputation: 406
Why dont you use fputcsv()
Click Here. For more information about this
Upvotes: 1