473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.php. This is the error message

Fatal error: Cannot break/continue 1 level





Registration.php

<?





if ($register1) {



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

include("includes/registration2.inc.php");



} elseif ($register2) {



include("includes/registration3.inc.php");



} else {



include("includes/registration1.inc.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("includes/registration1.inc.php");

break;

}

?>

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

if ($register1) {



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

include("includes/registration2.inc.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.php. This is the error message

Fatal error: Cannot break/continue 1 level







Registration.php

<?





if ($register1) {



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

include("includes/registration2.inc.php");



} elseif ($register2) {



include("includes/registration3.inc.php");



} else {



include("includes/registration1.inc.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("includes/registration1.inc.php");

break;

}

?>

Jul 17 '05 #2

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

Similar topics

5
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
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
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...
1
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...
6
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
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
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...
26
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)...
3
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.