How to edit a row -- not using database
Posted: Fri Mar 27, 2009 6:36 am
Hello,
I am a beginner in programming and I would like to build a PHP address book function where I can edit and delete single entry. I am using a flat file.
What I have done so far is I could populate all the data from the file into a html table. I added 2 additional column for the edit and delete. Refer to my screen shot. Part of my code is as shown:
Please guide me (I appreciate a detailed explanation as my logic is not good) of how to achieve this:
a) When I click the edit or delete link, it would select all the information on that row and then send it to another PHP
page
b) After a), how do I select the information and populate the data back to the page so the user can edit it
I think it could be achieved with URL parameter but I am not sure how to do it. Can you guide me on that.
Any hints or web page that able to solve this.
***************************************************************************************
<?php
$fp = fopen('contact.txt','r');
print "<table border=1><tr><td>First Name</td><td>Last Name</td><td>Email Address</td><td>Phone Number</td><td>Street Address</td>
<td>City</td><td>State</td><td>ZIP</td><td>Access Code</td><td>Action</td><td>Action</td></tr>";
while (!feof($fp)) {
$data = fgetcsv($fp,'1024',','); //get a row at a time
$num = sizeof($data);
print '<tr>';
foreach ($data as $value) {
//for($a=0;$a<sizeof($data);++$a) {
//if (!$data[$a]) {
if(!$value) {
echo "<td> </td>";
}
else {
echo "<td>$value</td>";
}
}
print '<td><a href = "abc.php?FirstName=".">Edit</a></td>';
print '<td><a href = "abc.php">Delete</a></td>';
print '</tr>';
}
print "</table>";
?>
**********************************************************************************
I am a beginner in programming and I would like to build a PHP address book function where I can edit and delete single entry. I am using a flat file.
What I have done so far is I could populate all the data from the file into a html table. I added 2 additional column for the edit and delete. Refer to my screen shot. Part of my code is as shown:
Please guide me (I appreciate a detailed explanation as my logic is not good) of how to achieve this:
a) When I click the edit or delete link, it would select all the information on that row and then send it to another PHP
page
b) After a), how do I select the information and populate the data back to the page so the user can edit it
I think it could be achieved with URL parameter but I am not sure how to do it. Can you guide me on that.
Any hints or web page that able to solve this.
***************************************************************************************
<?php
$fp = fopen('contact.txt','r');
print "<table border=1><tr><td>First Name</td><td>Last Name</td><td>Email Address</td><td>Phone Number</td><td>Street Address</td>
<td>City</td><td>State</td><td>ZIP</td><td>Access Code</td><td>Action</td><td>Action</td></tr>";
while (!feof($fp)) {
$data = fgetcsv($fp,'1024',','); //get a row at a time
$num = sizeof($data);
print '<tr>';
foreach ($data as $value) {
//for($a=0;$a<sizeof($data);++$a) {
//if (!$data[$a]) {
if(!$value) {
echo "<td> </td>";
}
else {
echo "<td>$value</td>";
}
}
print '<td><a href = "abc.php?FirstName=".">Edit</a></td>';
print '<td><a href = "abc.php">Delete</a></td>';
print '</tr>';
}
print "</table>";
?>
**********************************************************************************