vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   variable passing (https://vborg.vbsupport.ru/showthread.php?t=128031)

who is chris c 10-01-2006 10:40 PM

variable passing
 
i'm having a stupid moment here and cant figure out why the variables arnt passing
PHP Code:

if(!$step){$step=1;}

  if((
$step1 == 1) && ($agree == yes)){ header("/signup.php?step=2"); }
elseif((
$step1 == 1) && ($agree != yes)){ header("/signup.php?warn=yes"); }
elseif((
$step2 == 1) && ($agree == yes)){ header("/signup.php?step=3"); }
elseif((
$step2 == 1) && ($agree != yes)){ header("/signup.php?step=2&warn=yes"); } 


PHP Code:

         <form method="post" action="signup.php">
         <?if($warn==yes){?><b><?}?>In order to proceed, you must agree with the following Terms of Service:</b>
         <table width="100%">
          <tr>
           <td colspan="2">
           <div style="border:thin inset;background: #000022; padding:6px; height:175px; overflow:auto"><?=$html[1]?></div>
           </td>
          </tr>
          <tr>
           <td><input type="checkbox" name="agree" value="yes" style="background: #111111;"> <input type="hidden" name="step1" value="1"> <strong><nobr>I have read, and agree to abide by the Terms of Service.</nobr></strong></td>
           <td align="right"><input type="submit" value="next >>"></td>
          </tr>
         </table>
         </form>

that should be all i need to paste either its been too long since i've done any programming or i'm just an idiot either way its too hard getting back into things from a yr vacation

nico_swd 10-02-2006 06:53 AM

Try

header("Location: /signup.php?step=2");

EDIT:

Also, on a sidenote, you don't need the brackets {} if you only want to do one thing. So instead of
PHP Code:

if(!$step){$step=1;} 

You can simply do this
PHP Code:

if(!$step$step=1


EDIT 2:

There should be quotes around the "yes".
PHP Code:

$agree == 'yes' 


Guest190829 10-02-2006 07:37 AM

Quote:

Originally Posted by nico_swd
Try

header("Location: /signup.php?step=2");

EDIT:

Also, on a sidenote, you don't need the brackets {} if you only want to do one thing. So instead of
PHP Code:

if(!$step){$step=1;} 

You can simply do this
PHP Code:

if(!$step$step=1

EDIT 2:

There should be quotes around the "yes".
PHP Code:

$agree == 'yes' 


You can also use the switch statement, which in my personal opinion is alot cleaner than a bunch of if/elseif statements:

http://us3.php.net/switch

nico_swd 10-02-2006 07:49 AM

Yep, I prefer the switch() method as well. In his case he could do something like this:
PHP Code:


$case 
$step $agree;

switch (
$case)
{
     case 
'1yes':

            
header("Location: /signup.php?step=2");
            break;
     
     default:
     case 
'1no':

            
header("Location: /signup.php?warn=yes");
            break;

     
// And so on...
}

exit(); 


Adrian Schneider 10-02-2006 07:54 AM

Just another simpler (IMO) variation...
PHP Code:

switch (true)
{
    case (
$step == and $agree == 'yes'):
        
header('Location: /signup.php?step=2');
        break;


Your way is neat... I've never seen people do it like that.

who is chris c 10-02-2006 08:04 PM

thanks for the help so far but that didnt fix the problem i'm having its either not setting the values in
HTML Code:

<td><input type="checkbox" name="agree" value="yes" style="background: #111111;"> <input type="hidden" name="step1" value="1"> <strong><nobr>I have read, and agree to abide by the Terms of Service.</nobr></strong></td>
          <td align="right"><input type="submit" value="next ->"></td>

because $stepx (where step is 1 or 2) and $agree arnt setting it seems put the 2 vars at the top just echoing them before the if/switch(have it wrote both ways) but they arnt echoing anything so they arnt set not sure whats going on

nico_swd 10-02-2006 08:20 PM

Is the code you posted above the beginning of your page? If so, do you have register globals enabled? Try either changing all $step to $_POST['step'] and $agree to $_POST['agree'], or try placing this at the top of your page.
PHP Code:

extract($_POST); 

You can also try this to see which POST variables are received in this page.
PHP Code:

print_r($_POST); 

If this outputs an empty array, then does your form fail.

who is chris c 10-02-2006 09:08 PM

changing it to $_POST helped now i get the values: Array ( [agree] => yes [step1] => 1 [step] => 1 ) so they are stored and the switch is working just not liking
PHP Code:

switch (true)
{
    case (
$_POST['step1'] == and $_POST['agree'] == 'yes'):
echo 
"almost";        
header('Location: /signup.php?step=2');
echo 
"!!!!your here!!!!!";
        break;


the redefinition of the header: header('Location: /signup.php?step=2');
due to it already defined in the include

nico_swd 10-02-2006 09:33 PM

You cannot modify the header information after outputting data to the browser. Take out the first echo and it should work.

harmor19 10-02-2006 10:05 PM

Couldn't you write a function as well?


You can put the function at the top of your script, below the opening php tag.
PHP Code:

function checkValues($step$agree$page);
{
    if(
$step == && $agree == "yes")
    {
        
header('Location: ?step=$page');
    }
    else
    {
       
header('Location: ?step=$page&warn=yes');
    }



Where you're using the if/else or switch method you can replace it with
PHP Code:

checkValues($_POST['step1'], $_POST['agree'], $_POST['page']) 

In your first form add the HTML code below the opening form tag.
HTML Code:

<input type="hidden" name="page" value="1" />
Add the same HTML code to all the other forms but change "value="1"" to "value="2"" and value="3"".


All times are GMT. The time now is 06:34 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01436 seconds
  • Memory Usage 1,771KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_html_printable
  • (15)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete