Page 1 of 1

Just about complete but..............Help

Posted: Thu Dec 23, 2004 3:20 pm
by remasters
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]\">"."&nbsp;"."&nbsp;"."&nbsp;".
"<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,

Posted: Thu Dec 23, 2004 3:37 pm
by John Cartwright
When submitting it should submit the information to delete already.

you can access your array through $_POST

for example

$_POST['yourfieldnamehere']

Posted: Thu Dec 23, 2004 3:59 pm
by remasters
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,

Posted: Thu Dec 23, 2004 4:14 pm
by John Cartwright

Code: Select all

&lt;form action="delete.php" method="post"&gt; 
&lt;?PHP 

$dbfile = 'mytextfile.txt'; 
$contents = file($dbfile); 
for ($i=1,$j=1;$i&lt;count($contents);$i++,$j++){ 
implode("&lt;br&gt;\n",$getid = explode($SEP,trim($contents&#1111;$i]))).'&lt;br&gt;'.$i."&lt;br&gt;&lt;br&gt;\n"; 
$email = $getid&#1111;3]; 

echo "&lt;input type="text" size="15" name="firstname" value="$getid&#1111;1]"&gt;". 
"&lt;input type="text" size="15" name="lastname" value="$getid&#1111;2]"&gt;". 
"&lt;input type="text" size="25" name="email" value="$getid&#1111;3]"&gt;". 
"&lt;input type="text" size="10" name="account" value="$getid&#1111;4]"&gt;". 
"&lt;input type="text" size="25" name="accountid" value="$getid&#1111;5]"&gt;"."&amp;nbsp;"."&amp;nbsp;"."&amp;nbsp;". 
"&lt;input type="checkbox" name="$j"&gt;"."&lt;br&gt;"; 

} 

?&gt; 
&lt;p align="left"&gt;&lt;input type="submit" 
name="delete" value="delete"&gt;&lt;/p&gt;

Code: Select all

&lt;?php

echo '&lt;pre&gt;';
var_dump($_POST);
echo '&lt;/pre&gt;';

?&gt;
you can access the specific vars as I said erlier by $_POST['yourvarhere'].. you will get a list of them that were sent to delete php by viewing the var dump

Posted: Thu Dec 23, 2004 4:55 pm
by Hibba
Or to have a dump of the variables in an array:

Code: Select all

<?php

echo '<pre>';
print_r($_POST);
echo '</pre>';

?>

Posted: Thu Dec 23, 2004 4:56 pm
by Hibba
actually, i think that is the same thing, so nevermind...

Posted: Fri Dec 24, 2004 4:24 pm
by remasters
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

Posted: Fri Dec 24, 2004 5:22 pm
by rehfeld
you could use sessions to store a 'already_deleted' variable of some sort, or just set a cookie