0

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. 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?

7 Answers 7

3

You are submitting form via POST method, try $_POST['typeid'];

Alternatively change method to GET.

Sign up to request clarification or add additional context in comments.

Comments

2

Since you are using method="post" in form, you should use

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

$_GET in PHP is used when you use HTTP GET method (method="get" in form tag).

Comments

2

You're using the $_GET array while you're posting your infos.

You should use the $_POST array, or even the $_REQUEST array which handles both POST and GET.

Comments

1

You have method="post" so the data is placed in the message body and not the query string. It will be accessible via $_POST not $_GET.

Comments

1

You are using method="post" so look in $_POST :)

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

HTH

Comments

1

Since you are using HTTP POST method in your <form> you need to give the code as:

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

Else, in the HTML change this:

<form method="get">

Comments

1

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'] .

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 
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.