473,785 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

break out of IF statement

Jay
G'day all

This registration form checks for the submit button then displays the next form from the include statement. But before it displays the next form it will check to make sure the user has entered details correctly and give error messages of whats missing before displaying the original form again. My problem is that I can't exit from the 'if' statement, it brings up the first form as desired, but I can't get it to quit there. I tried using the break; function but it needs to be in a 'do while' sort of loop before it will let you break out of it. I tried putting the if statement inside a do while like this one



do {

if ($cond1) {

...

}

} while(0);





Bt I couldn't seem to get it to work, probably because part of the code is being included? Any ideas? All I want it to do is stop processing the rest of the IF statement in registration.ph p. This is the error message

Fatal error: Cannot break/continue 1 level





Registration.ph p

<?





if ($register1) {



include("includ es/registration1-check.inc.php") ;

include("includ es/registration2.i nc.php");



} elseif ($register2) {



include("includ es/registration3.i nc.php");



} else {



include("includ es/registration1.i nc.php");



}





?>



registration1-check.inc.php

<?

// reset errorstop

$errorstop = 0;



if (!$username) {

$error = "Please enter a username<br>";

echo $error;

$errorstop = 1;

}



if (!$password1) {

$error = "Please enter a Password<br>";

echo $error;

$errorstop = 1;

}





if ($errorstop == 1 ) {

// show the original form again

include("includ es/registration1.i nc.php");

break;

}

?>

Jul 17 '05 #1
1 18901
In registration1-check.inc.php return $errorstop, then structure your loop in registration.ph p like this:

if ($register1) {



if(!include("in cludes/registration1-check.inc.php") ) {

include("includ es/registration2.i nc.php");

}

}

But what you should do is restructure your code. Using include files in this manner is a very bad practice.

Uzytkownik "Jay" <gy****@hotmail .com> napisal w wiadomosci news:bt******** ***@bigblue.net .au...
G'day all

This registration form checks for the submit button then displays the next form from the include statement. But before it displays the next form it will check to make sure the user has entered details correctly and give error messages of whats missing before displaying the original form again. My problem is that I can't exit from the 'if' statement, it brings up the first form as desired, but I can't get it to quit there. I tried using the break; function but it needs to be in a 'do while' sort of loop before it will let you break out of it. I tried putting the if statement inside a do while like this one





do {

if ($cond1) {

...

}

} while(0);







Bt I couldn't seem to get it to work, probably because part of the code is being included? Any ideas? All I want it to do is stop processing the rest of the IF statement in registration.ph p. This is the error message

Fatal error: Cannot break/continue 1 level







Registration.ph p

<?





if ($register1) {



include("includ es/registration1-check.inc.php") ;

include("includ es/registration2.i nc.php");



} elseif ($register2) {



include("includ es/registration3.i nc.php");



} else {



include("includ es/registration1.i nc.php");



}





?>



registration1-check.inc.php

<?

// reset errorstop

$errorstop = 0;



if (!$username) {

$error = "Please enter a username<br>";

echo $error;

$errorstop = 1;

}



if (!$password1) {

$error = "Please enter a Password<br>";

echo $error;

$errorstop = 1;

}





if ($errorstop == 1 ) {

// show the original form again

include("includ es/registration1.i nc.php");

break;

}

?>

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2543
by: Ann | last post by:
I have trouble sometimes figuring out where break and continue go to. Is there some easy way to figure it out, or a tool? TIA Ann
25
3920
by: chunhui_true | last post by:
In <<expert c>>I know the break in if wich is scoped in switch is break the switch,like: switch c case 1: if(b){ break; } ...... But like this: while(a){
55
3732
by: Ennixo | last post by:
hi, do you know where i can find some ebooks or websites talking about C# optimisation ? for exemple, i just learned that ++i is faster than i++. i would like to know more about the things that can make code faster than fast. thank you.
1
1472
by: Neo | last post by:
I am in dire need of a break statement in VB.NET language. I have several pieces of code that would have much cleaner look and much less deeper if/else/endif nests IF VB.NET HAS A BREAK STATEMENT OR SOMETHING SIMILAR. Will VB.NET has a break statement in the coming Whidbey release?
6
1729
by: David | last post by:
I know that by some reasons... the use of "break;" in java language is not correct, is there any similar problems with c#????
26
10221
by: Alexander Korsunsky | last post by:
Hi! I have some code that looks similar to this: -------------------------------------------- char array = "abcdefghij"; for (int i = 0; i < 10; i++) {
22
2540
by: Cogito | last post by:
For the first time, I'm attempting to write a small Javascript program using one on the online reference sites. I need some confirmation as to the behaviour of the break statement. In the following code: for ( row = 0 ; row <= 7 ; row++ ) A <---- { for ( col = 0 ; col <=7 ; col++ ) B <---- {
26
3237
by: a.mil | last post by:
I am programming for code-speed, not for ansi or other nice-guy stuff and I encountered the following problem: When I have a for loop like this: b=b0; for (a=0,i=0;i<100;i++,b--) { if (b%i) continue; a=1; }
3
31444
by: Yansky | last post by:
Hi, I've looked through the tutorial on w3cschools.com, but I'm still uncertain as to the difference between using break and using return. If I have a simple "for" loop that I want to stop if a condition is met, should I use break or return to stop the loop? e.g. is something like this ok? Would using return do the same thing? var dow = ;
0
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9954
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8979
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.