Page 1 of 1

Empty parameter passing...

Posted: Fri Oct 11, 2002 9:56 pm
by iguana
OS: Win2k,apache 1.3 for win, php 4.2.2

I encounter the parameter $choice is empty from the below statement. Pls help me.
:( :(
Here I face the parameter passing with empty value.I attach the code here:
call.php
--------
<?php
// call.php
require("standard.php") ;
//$choice = $_POST["$choice"]; // temp
//echo ("ChoiceX: " . $choice); // temp
if (!$choice){
echo ("Choice1: " . $choice); // temp
GenerateFrontPage();
} else if ($choice == "choice1"){
echo ("Choice2: " . $choice); // temp
}
else if ($choice == "choice2"){
echo ("Choice3: " . $choice); // temp
}
?>

standard.php
------------
<?php
function GenerateFrontPage() {
//printf("<FORM ACTION=call.php METHOD=POST>");
printf("<FORM METHOD=post ACTION=call.php>");
printf("<INPUT TYPE=\"submit\" NAME=\"choice\" VALUE=\"choice1\">");
printf("&nbsp; &nbsp; &nbsp;");
printf("<INPUT TYPE=\"submit\" NAME=\"choice\" VALUE=\"choice2\">");
printf("<BR>");
printf("<BR>");
}
?>

Here I would like to say thank you for you all.Because I cracking my head for 2 weeks to solve this.I'm a beginner.

Thank you.

tcc

Posted: Fri Oct 11, 2002 10:20 pm
by volka
which version of php are you using? (if unsure use phpinfo(); )
If version >= 4.1.0 add

Code: Select all

... // call.php
echo '&lt;pre&gt;'; print_r($_REQUEST); echo '&lt;/pre&gt;';
...
to see if there's any data transmitted.
if version <= 4.1.0 test it with

Code: Select all

... // call.php
echo '&lt;pre&gt;'; print_r($HTTP_GET_VARS); print_r($HTTP_POST_VARS); echo '&lt;/pre&gt;';
read http://www.php.net/manual/en/reserved.v ... ables.post and http://forums.devnetwork.net/posting.php?t=511

--- suggestions ---
printf("<FORM METHOD=post ACTION=call.php>");
printf("<INPUT TYPE=\"submit\" NAME=\"choice\" VALUE=\"choice1\">");
since you already started to put some properties in quotes do it everywhere. Close all tags you've opened, use <tag/> to close an element immediately

Code: Select all

&lt;FORM METHOD="post" ACTION="call.php"&gt;
   &lt;INPUT TYPE="submit" NAME="choice" VALUE="choice1" /&gt;
...
&lt;/FORM&gt;
printf is for formatted output. Your format is a static string so use print or echo
  • There are three types of string-literals in PHP, i.e.
  • "string"
  • 'string'
read http://www.php.net/manual/en/language.types.string.php to learn more about it.
If you use single-quotes as literal delimeters you don't have to escape double-quotes, i.e.

Code: Select all

print('&lt;FORM METHOD="post" ACTION="call.php"&gt;');
you can leave and enter php-blocks as you want, i.e.

Code: Select all

&lt;?php
function GenerateFrontPage() {
***
&lt;FORM METHOD="post" ACTION="call.php"&gt;
&lt;INPUT TYPE="submit" NAME="choice" VALUE="choice1"&gt;

&lt;INPUT TYPE="submit" NAME="choice" VALUE="choice2"&gt;
&lt;BR/&gt;&lt;BR/&gt;
&lt;?php
} 
***
(instead of *** think a question mark followed by a greater than - they are completely eaten by the board right now :( )
anything outside the php-block will be direct output

Posted: Fri Oct 11, 2002 10:43 pm
by zebrax
try taking out the $

Code: Select all

$choice = $_POST&#1111;"$choice"]; 

should be

$choice = $_POST&#1111;"choice"];

Posted: Fri Oct 11, 2002 10:47 pm
by volka
it's so simple and I started to be such a smart-ass Image

Posted: Fri Oct 11, 2002 11:23 pm
by iguana
Thank very much for you all to solve my "BIG" problem. I really appreciate it. Thank again.