Jump to content

Checking if all $msg's are empty.


silentkillzr

Recommended Posts

if(!isset($msg) and !isset($msg1) and !isset($msg2) and !isset($msg3) and !isset($msg4) and !isset($msg5) and !isset($msg6) and !isset($msg7) and !isset($msg8) and !isset($msg9) and !isset($msg10)) { $regsuccess = "yes" }

 

And i cant seem to get it working, all i get is "Parse error: parse error in blah blah.php on line 101 which this is on."

Link to comment
Share on other sites

Why not put all errors in an array?

 

exampe:

$msg = array();

if(<INVALIDUSERNAME>)

    $msg[] = 'Invalid username';

if(<INVALIDPASSWORD>)

    $msg[] = 'Invalid Password';

if(<INVALID_EMAIL>)

    $msg[] = 'Invalid Email';

 

if(count($msg) == 0)

    echo 'Yes';

else

    foreach($msg as $error)

        echo $error.'<br />';

Link to comment
Share on other sites

Well, for starters it may help if this were in an array, and in doing so you could check if each message within the array was set. But thats another story. For now this should be what you're after.

 

if (
!isset($msg) && 
!isset($msg2) &&
!isset($msg3) &&
!isset($msg4) &&
!isset($msg5) &&
!isset($msg6) &&
!isset($msg7) &&
!isset($msg8) &&	
!isset($msg9) &&
!isset($msg10)
) { 
$regsuccess = "yes" 
}

Link to comment
Share on other sites

I assume your tyring to show error message and also set a flag "$success" which tells the script whether or not to process a certain part.

 

This would be a proper way to show error messages and success message.

 

To answer your question,

Put $msg into a array, Like You could have $error['invalid_email']  $error['invalid_name'] , $error['invalid_phone_number'] etc..

Then use empty() to check it.. See the example below.

 

<?php

//set variables
$success = ""
$error     = array();

if( <invalid email check here>){

   $error['invalid_email'] = "Fix this";
}

if(empty($error)){

  $success = " Thanks ";

// Process further...



}

?>
<!-- html page -->

<?php if(!empty($success)) echo $success; ?>
<form action="" method="post">
<dl>
   <dt><label for="Email">Email</label></dt>
    <dd><input type="text" value="" id="email" name="email"/><?php if(!empty($error)) echo "<span>{$error['invalid_email']}</span>" ?></dd>
</dl>
</form>

 

 

btw I did not test that code, but its the general idea.

 

 

You can also pass many parameters to isset()

 

so you could do this, (which is really bad and lazy, you should use an array for $msg)


if( ! isset($msg1,$msg2,$msg3,$msg4,$msg5,$msg6,$msg7,$msg9)){


}

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.