DominusMors
DominusMors

Reputation: 129

PHP passing a variable from HTML to another PHP file

Ok, so im making and admin page which requires to deletes entries from databases, and i cant figure out how to pass the id variable of the post to another php file.

echo '<form method="post" action="delete_member_post.php" style="text-align:center;" id="delete_post">';
echo '<p style="text-align:center; font-size:20px;"> <font font-size:20px face="Rockwell" color="#680000"> Select post to delete:</font>';
echo '<select name="delete" form="delete_post">';
for ($z=1; $z<=$text["id"]; $z++)
{
    $c=$c+1;
    echo '<option value="' . $c . '">' . $c . ' </option>';
}
echo '</select> <br>';
echo '<input type="submit" value="Submit Choice"=>';
echo '</form>';

After the loop in the PHP file im echoing $c (based on how many entries the DB has) and its printing my options.

In the other file im using

$i = $_POST["$c"];  

to get the id that had been chosen but all i get is the same error, Undefined variable and Undefined index.

Thanks for your time.

Upvotes: 3

Views: 1149

Answers (3)

Drown
Drown

Reputation: 5982

$_POST['delete'] will return the value of the option that has been selected in the form.

From what I understand this is what you want, if the user has selected the ID 7 in the dropdown before submitting the form, $_POST['delete'] will contain the value 7 .

Upvotes: 2

DBWhite
DBWhite

Reputation: 128

I understand you want to send final value (count) of variable $c to another file? You should save the value of that variable in a hidden input field after the loop:

<input type="hidden" name="count" id="count" value="<?= $c  ?>" />

Now you can access it with

$i = $_POST["count"]; 

Upvotes: 1

SkyDriver2500
SkyDriver2500

Reputation: 57

Using php create a file that will contain the variable and its value, then include that file using include "file.php", then the variable is usable in the file you include file.php.

Upvotes: 0

Related Questions