Forum Moderators: coopster

Message Too Old, No Replies

How to pass parameters?

         

may_hem1

5:15 am on Sep 25, 2003 (gmt 0)

10+ Year Member



Hi, I am moving from ASP to PHP but am having trouble with even the simplest task. I want to pass a parameter from a form to a processing page. Here is the code of both files:

MyForm.html

<html>
<head>
<title>my form</title>
</head>
<body>
<form action=process.php METHOD=post>
<input type=checkbox name=mychoice value="210">
<input type=submit value=Confirm>
</form>
</body>
</html>

process.php

<html>
<head>
<title>process form</title>
</head>
<body>
<?php echo ($mychoice);?>
</body>
</html>

So I go to IIS, select MyForm.html, and browse it. It opens up in Internet Explorer. I tick the box and click SUBMIT. The PHP page opens and gives an error "Notice: Undefined variable" for the form checkbox "mychoice".

How can I fix this?

Thanks,
May

jatar_k

5:23 am on Sep 25, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hello may_hem1,

you will need to access the variable through the $_POST array

so

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

though a bit of shorthand for you. This means the same thing

<?= $_POST['mychoice']?>

if you jst want to echo the value of a var

have a look here for $_POST among others
PHP Predefined variables [ca.php.net]

may_hem1

5:44 am on Sep 25, 2003 (gmt 0)

10+ Year Member



Great, thanks!

But I've found endless "Undefined Variable" and "Undefined Index" errors in ready-to-use code I've downloaded from reputable sites. Of 10 different guestbook files, not one has worked without giving an "Undefined Variable" error.

Is there something that should be configured after installing PHP on IIS? Surely all this code can't be problematic?

Thx!
May

jatar_k

5:49 am on Sep 25, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Using Register Globals [ca3.php.net]

Perhaps the most controversial change in PHP is when the default value for the PHP directive register_globals went from ON to OFF in PHP 4.2.0. Reliance on this directive was quite common and many people didn't even know it existed and assumed it's just how PHP works. This page will explain how one can write insecure code with this directive but keep in mind that the directive itself isn't insecure but rather it's the misuse of it.

so anything developped before version 4.2.0 may use old settings.

Take a look at using extract [ca3.php.net] as a quick fix for older scripts.

may_hem1

6:39 am on Sep 25, 2003 (gmt 0)

10+ Year Member



jatar_k, you're a star!

I had a look at Extract but don't understand what it can do and how I should use it in older scripts.

The description says "This function is used to import variables from an array into the current symbol table.". What's a symbol table?

Thx,
May

jatar_k

7:00 am on Sep 25, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



use it like so

extract($_POST);

then you dont have to use

<?= $_POST['mychoice']?>

you can just use

<?= $mychoice?>

;)

may_hem1

9:28 am on Sep 25, 2003 (gmt 0)

10+ Year Member



Cool, thanks Jatar_k!

I'm flying in PHP now!

May ;o)

Argie

11:13 pm on Sep 26, 2003 (gmt 0)

10+ Year Member



Jatar_k, may_hem1 is right...

ˇˇˇYOU ARE THE MAN!

I had the same problem and thanks to you, as may_hem1 said...

I'm flying in PHP now!

Thank you very much, both.

jatar_k

11:37 pm on Sep 26, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



glad I could help.