Jump to content

Hard to describe, I am looking for something like 'return' but for IF


Recommended Posts

Wrote something small just to get my point accross

 

<?php

if (isset($sumbited))
{//process form

   if (isset($error))
    {echo "Your username is too long";
      // at this point I would like it to go to the 'else' right below. @ Section 751
    }

}
else // THIS IS WHERE I WANT IT TO GO
{echo "blah blah"; // form data
}

?>

<?php
$done = 0;

if (isset($sumbited))
{//process form

   if (isset($error))
    {echo "Your username is too long";
    }
   else { $done = 1; }

}
if ($done == 0)
{echo "blah blah"; // form data
}

?>

 

edit: changed == 1 to == 0, typed it wrong originally

Instead of trying to make it go from that place to that other place, I think you need to rethink your structure.  You would normally use something like goto but that is spaghetti code programming and is bad practice.  What is your overall goal with this?

Goto?  Yuck!!!  If you must use a goto, set what you want to do in a function, and then call the function..  This helps document your code as you go too, and is one step closer to OOP.

 

 

function doSomething() {
      // THIS IS WHERE I WANT IT TO GO
     echo "Your username is too long";
     echo "blah blah"; // form data
}


/*** MAIN PROGRAM BODY ****/

if ($sumbited)
{//process form

   if ($error) {
       doSomething();
    }


}

 

or you could do

 

      if ( $submitted && $error ) {
             doSomething();
      }

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.