2015-02-07 23:09
浏览 88


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++)
    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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongzang7182 2015-02-07 23:17

    $_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 .

    点赞 打赏 评论
  • duanlei20082008 2015-02-07 23:16

    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.

    点赞 打赏 评论
  • drvpv7995 2015-02-07 23:17

    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"]; 
    点赞 打赏 评论

相关推荐 更多相似问题