Hi,
I just entered into php before a few months. And haven’t got into MySQL till now. I wanted to have good practice on php and it’s file writing and reading before i get into MySQL…
Well, Until a few days every thing was correct. I made some small software also based on php and HTML. Such as some scripts, Emailing, Contacting us and shoutbox etc…
Well, Not I need help. Here I want to delete a line from a text file… THE code will say more clearly…
This is a simple project. In which I have used 3 files… test.php, testdb.txt(FOR DATABASE) and admin.php
Here are the codes, once you have red the code. I would able to describe what I want exactly,
code of test.php
<?php
$db = "testdb.txt";
$form = "<form method="post" action="test.php">
Entry Number ; <input name="entry" type="text" size="20">
<input name="submit" type="submit" value="submit">
</form>";
$entry_num = $_POST["entry"];
$entry_to_write = "<br>It's entry number $entry_num.";
if($_POST["submit"] == submit)
{
$f_handle = fopen($db, 'a');
fwrite($f_handle,$entry_num."n");
fclose($f_handle);
echo "<b>Entry Entered into system</b>";
$file = file("testdb.txt");
array_reverse($file);
foreach($file as $line)
echo "$line<br>";
}
else
{
echo $form;
}
?>
code of admin.php
<?php
$db = "testdb.txt";
$del_form = "<form method="post" action="admin.php">
Line to delete >>> <input name"del" type="text" size="10">
<input name="del_now" type="submit" value="del_now">
</form>";
$login_form = "<form method="post" action="admin.php">
Line to delete >>> <input name"pass" type="text" size="10">
<input name="del_now" type="submit" value="pass">
</form>";
if($_POST["pass"] == 123)
{
echo $del_form;
$file = file("testdb.txt");
$line_to_del = $_POST["del_now"];
unset($file[$line_to_del-1]);
array_reverse($file);
foreach($file as $line);
echo $line;
}
else
{
echo $login_form;
}
?>
Now, the problem is, Almost the file writing and reading in reverse order is perfect… But the admin.php is making problem while i want to delete a line from testdb.txt
for example, if 10 people have inserted the entry… so each entry is set up as a line… So when i want to delete entry four… I would delete line four… But I am not able to delete any line…
Please help me…
Thanks…
FAISAL!