Jump to content

Not showing error is no input is given


Xtremer360

Recommended Posts

For one, you'll allowing the script to continue running even after a fatal error.

 

Take this example

<?php

$foo = 'no';
$bar = 'yes';

if( $foo == 'no' )
echo 'Fatal error!';
if( $bar == 'yes' )
echo 'Things are working as expected';

?>

Will output

Fatal error!Things are working as expected

 

While

 

<?php

$foo = 'no';
$bar = 'yes';

if( $foo == 'yes' ) {
if( $bar == 'yes' )
	echo 'Things are working as expected';
} else
echo 'Fatal error!';


?>

outputs

Fatal error!

 

This is a very basic example, and in a complex situation like yours you may have a TON of nested ifs. In this case, I would put everything into a function, then you can simply use a return to stop the function when you hit an error.

 

<?php

$foo = 'no';
$bar = 'yes';

echo checkThis( $foo, $bar );

function checkThis( $arg1, $arg2 ) {

if( $arg1 != 'yes' )
	return 'Error - First argument was not a yes';
if( $arg2 != 'yes' )
	return 'Error - Second argument was not a yes';

return 'Both arguements were yes';

}


?>

 

Hope that helps.

Link to comment
Share on other sites

What I'm trying to correct is the part that checks to see if question1 and question2 have a selection made that has a value bigger than 0 because the option value with 0 is the -select- option. Because when I fill out my registration form it bypasses the fact that there wasn't a selection made for those two dropdowns.

 

Link to comment
Share on other sites

Well, you're checking a ton of variables that haven't been defined, unless you're working with register_globals.

 

Lines 51-60 create the variables you're trying to check for in lines 16-21 and lines 24 and 25. For some reason you actually check the right variables on lines 22 and 23

Link to comment
Share on other sites

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.