简体   繁体   English

在PHP表单之间传递变量。

[英]Passing variables between PHP forms.

This is probably a really easy question but its early so yeah... 这可能是一个非常简单的问题,但它还早...

Basically I have a form: 基本上我有一种形式:

<form name="varsForm" action="step2.php" id="formID" method="post">

And as I understand it within this for I created some hidden variables. 并且据我所知,我为此创建了一些隐藏变量。 as follows: 如下:

<input type="hidden" id="typeid" name="typeid" value="1" />

Because step2.php is set as an action, I though I was correct in assuming that the hidden variables would be passed to step2.php. 因为将step2.php设置为操作,所以我假设隐藏变量将传递给step2.php是正确的,尽管我是正确的。 However when I try to call them I am confronted with errors. 但是,当我尝试给他们打电话时,我遇到了错误。 I try and call them simply as follows: 我尝试简单地称呼它们如下:

<?php echo $_GET['typeid']; ?>

But it says that caseid is an undefined index, I assume I am not calling it correctly, anyone just put me right please? 但是它说caseid是一个未定义的索引,我想我没有正确地调用它,有人请问我对吗?

You are submitting form via POST method, try $_POST['typeid']; 您正在通过POST方法提交表单,请尝试$_POST['typeid'];

Alternatively change method to GET . 或者将方法更改为GET

Since you are using method="post" in form, you should use 由于您在表单中使用method =“ post”,因此应使用

<?php echo $_POST['typeid']; ?>

$_GET in PHP is used when you use HTTP GET method (method="get" in form tag). 当您使用HTTP GET方法(在表单标记中为method =“ get”)时,将使用PHP中的$ _GET。

You're using the $_GET array while you're posting your infos. 发布信息时使用的是$_GET数组。

You should use the $_POST array, or even the $_REQUEST array which handles both POST and GET. 您应该使用$_POST数组,甚至使用同时处理POST和GET的$_REQUEST数组。

You have method="post" so the data is placed in the message body and not the query string. 您具有method="post"因此数据将放置在消息正文中,而不是查询字符串中。 It will be accessible via $_POST not $_GET . 可以通过$_POST而不是$_GET

You are using method="post" so look in $_POST :) 您正在使用method="post"因此请查看$ _POST :)

<?php echo $_POST['typeid']; ?>

HTH 高温超导

Since you are using HTTP POST method in your <form> you need to give the code as: 由于您在<form>中使用HTTP POST方法,因此需要提供以下代码:

<?php echo $_POST['typeid']; ?>

Else, in the HTML change this: 否则,在HTML中进行以下更改:

<form method="get">

You have method attribute in the form set to POST so values passed to step2.php will not be available in $_GET , it will be available in $_POST so to access the value you need to use $_POST['typeid'] . 您已将方法属性的形式设置为POST,因此传递给step2.php的值将在$ _GET中不可用,在$ _POST中将可用,因此要访问需要使用$ _POST ['typeid']的值。

And also Some times to avoid warnings OR notifications regarding index ( such as undefined index ) , you can first check for its existence and then process 并且有时为了避免有关索引的警告或通知(例如未定义的索引),您可以首先检查其存在然后处理

Some what like this 有些像这样

if (array_key_exists('typeid', $_POST) )
{
     $typeid = $_POST['type_id'];
    // And do what ever you want to do with this value 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM