Just about complete but..............Help
Moderator: General Moderators
Just about complete but..............Help
Okay I have a textfile that I am looping thru and outputing the information to a new page.
Everything works great. But if you notice I am also displaying a checkbox with each line I post. This is so I can delete the line number/contents from the file.
Here lies the problem. It displays fine, but once I hit the submit button to my new page(for testing purposes before I actually remove the lines from the textfile) I can't seem to pass the information.
The new page(delete.php) should just show the lines that were checked. Note that I a am naming each checkbox the value of $j, which would be the line number from the textfile.
I hope this isn't too confusing. I am basically wondering how I would store the values of checkbox in an array and pass it to delete.php.
Here is what I have so far.
<form action="delete.php" method="post">
<?PHP
$dbfile = 'mytextfile.txt';
$contents = file($dbfile);
for ($i=1,$j=1;$i<count($contents);$i++,$j++){
implode("<br>\n",$getid = explode($SEP,trim($contents[$i]))).'<br>'.$i."<br><br>\n";
$email = $getid[3];
echo "<input type=\"text\" size=\"15\" name=\"firstname\" value=\"$getid[1]\">".
"<input type=\"text\" size=\"15\" name=\"lastname\" value=\"$getid[2]\">".
"<input type=\"text\" size=\"25\" name=\"email\" value=\"$getid[3]\">".
"<input type=\"text\" size=\"10\" name=\"account\" value=\"$getid[4]\">".
"<input type=\"text\" size=\"25\" name=\"accountid\" value=\"$getid[5]\">"." "." "." ".
"<input type=\"checkbox\" name=\"$j\">"."<br>";
}
?>
<p align="left"><input type="submit"
name="delete" value="delete"></p>
Any and all help would be greatly appreciated.
Thanks,
Everything works great. But if you notice I am also displaying a checkbox with each line I post. This is so I can delete the line number/contents from the file.
Here lies the problem. It displays fine, but once I hit the submit button to my new page(for testing purposes before I actually remove the lines from the textfile) I can't seem to pass the information.
The new page(delete.php) should just show the lines that were checked. Note that I a am naming each checkbox the value of $j, which would be the line number from the textfile.
I hope this isn't too confusing. I am basically wondering how I would store the values of checkbox in an array and pass it to delete.php.
Here is what I have so far.
<form action="delete.php" method="post">
<?PHP
$dbfile = 'mytextfile.txt';
$contents = file($dbfile);
for ($i=1,$j=1;$i<count($contents);$i++,$j++){
implode("<br>\n",$getid = explode($SEP,trim($contents[$i]))).'<br>'.$i."<br><br>\n";
$email = $getid[3];
echo "<input type=\"text\" size=\"15\" name=\"firstname\" value=\"$getid[1]\">".
"<input type=\"text\" size=\"15\" name=\"lastname\" value=\"$getid[2]\">".
"<input type=\"text\" size=\"25\" name=\"email\" value=\"$getid[3]\">".
"<input type=\"text\" size=\"10\" name=\"account\" value=\"$getid[4]\">".
"<input type=\"text\" size=\"25\" name=\"accountid\" value=\"$getid[5]\">"." "." "." ".
"<input type=\"checkbox\" name=\"$j\">"."<br>";
}
?>
<p align="left"><input type="submit"
name="delete" value="delete"></p>
Any and all help would be greatly appreciated.
Thanks,
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Hey thanks for your quick reply. I tried using the delete, but it doesn't display anything.
<?PHP
Echo $delete;
?>
Result displayed is delete.
Which should display array.
Where would I insert the $Post at in my current code? And if I might ask, in delete.php how would I display that it has been passed? I can step thru the array, I just need to get it there.
Also, since I am just giving my checkbox the name of the line number, shouldn't I be able to just get the name, so I know what to delete, or should I give it a standard name such as getCheckbox, and assign the value of the checkbox to the line number?
Thanks again,
<?PHP
Echo $delete;
?>
Result displayed is delete.
Which should display array.
Where would I insert the $Post at in my current code? And if I might ask, in delete.php how would I display that it has been passed? I can step thru the array, I just need to get it there.
Also, since I am just giving my checkbox the name of the line number, shouldn't I be able to just get the name, so I know what to delete, or should I give it a standard name such as getCheckbox, and assign the value of the checkbox to the line number?
Thanks again,
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
<form action="delete.php" method="post">
<?PHP
$dbfile = 'mytextfile.txt';
$contents = file($dbfile);
for ($i=1,$j=1;$i<count($contents);$i++,$j++){
implode("<br>\n",$getid = explode($SEP,trim($contentsї$i]))).'<br>'.$i."<br><br>\n";
$email = $getidї3];
echo "<input type="text" size="15" name="firstname" value="$getidї1]">".
"<input type="text" size="15" name="lastname" value="$getidї2]">".
"<input type="text" size="25" name="email" value="$getidї3]">".
"<input type="text" size="10" name="account" value="$getidї4]">".
"<input type="text" size="25" name="accountid" value="$getidї5]">"."&nbsp;"."&nbsp;"."&nbsp;".
"<input type="checkbox" name="$j">"."<br>";
}
?>
<p align="left"><input type="submit"
name="delete" value="delete"></p>Code: Select all
<?php
echo '<pre>';
var_dump($_POST);
echo '</pre>';
?>Or to have a dump of the variables in an array:
Code: Select all
<?php
echo '<pre>';
print_r($_POST);
echo '</pre>';
?>Thanks guys, that did the job. Now I have the form deleting the lines I need it to.
Now I have a secondary problem, when I hit the delete button on the form it deletes everything properly. I have it posting to itself, via the post php self. But the problem I now have is that if I hit the refresh button on the browser it deletes more lines.
I am testing for the isset($delete) but as with isset once $delete has been set, it will delete on refresh. I tried using the unset($delete) but to no avail. Still deleting.
Can someone point me to the proper way of getting around this problem without having to post to a different form then redirecting back to the original form?
Any and all help would be greatly appreciated.
Thanks,
Remasters
Now I have a secondary problem, when I hit the delete button on the form it deletes everything properly. I have it posting to itself, via the post php self. But the problem I now have is that if I hit the refresh button on the browser it deletes more lines.
I am testing for the isset($delete) but as with isset once $delete has been set, it will delete on refresh. I tried using the unset($delete) but to no avail. Still deleting.
Can someone point me to the proper way of getting around this problem without having to post to a different form then redirecting back to the original form?
Any and all help would be greatly appreciated.
Thanks,
Remasters