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.
好的,im创建和管理页面需要从数据库中删除条目,我不知道如何将post的id变量传递给另一个php文件。
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.
在PHP文件中的循环之后,im将响应$c(基于DB有多少项)并打印我的选项。
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.
要获得已选择的id,但得到的是相同的错误,未定义的变量和未定义的索引。
Thanks for your time.
谢谢你的时间。
3 个解决方案
#1
2
$_POST['delete']
will return the value
of the option that has been selected in the form.
$_POST['delete']将返回在表单中选择的选项的值。
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
.
根据我的理解,这正是您想要的,如果用户在提交表单之前在下拉菜单中选择了ID 7, $_POST['delete']将包含值7。
#2
1
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:
我知道你想把变量$c的最终值(计数)发送到另一个文件?循环结束后,应将该变量的值保存在一个隐藏的输入字段中:
<input type="hidden" name="count" id="count" value="<?= $c ?>" />
Now you can access it with
现在你可以用
$i = $_POST["count"];
#3
0
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.
使用php创建一个包含变量及其值的文件,然后使用include“file”包含该文件。然后该变量在包含file.php的文件中是可用的。
#1
2
$_POST['delete']
will return the value
of the option that has been selected in the form.
$_POST['delete']将返回在表单中选择的选项的值。
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
.
根据我的理解,这正是您想要的,如果用户在提交表单之前在下拉菜单中选择了ID 7, $_POST['delete']将包含值7。
#2
1
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:
我知道你想把变量$c的最终值(计数)发送到另一个文件?循环结束后,应将该变量的值保存在一个隐藏的输入字段中:
<input type="hidden" name="count" id="count" value="<?= $c ?>" />
Now you can access it with
现在你可以用
$i = $_POST["count"];
#3
0
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.
使用php创建一个包含变量及其值的文件,然后使用include“file”包含该文件。然后该变量在包含file.php的文件中是可用的。