Warning: Invalid argument supplied for foreach() in /xxx/xxxx/xxx/xxxxx/user.class.php on line 127
The bit of code in question is this:
user.class.php
public function display_notice($action)
{
echo "<h3>";
foreach ($this -> noticeCode as $element => $value)
{
if (!empty ($value))
{
switch($action)
{
case 'login': echo "<br>Login: ";new Message($value); break;
case 'register': echo "<br>Register: ";new Message($value); break;
}
}
}
echo '</h3>';
}
Is there something wrong with that foreach? Here is the entire user_cp.php file where the function is called:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>xxx</title>
<!-- Stylesheet -->
<link rel="stylesheet" type="text/css" href="xxx" />
<!-- Javascript codes -->
<script src="xxx" type="text/javascript"></script>
<script src="xxx" type="text/javascript"></script>
<script type="text/javascript">
var FullscreenrOptions = { width: 1920, height: 1080, bgID: '#bgimg' };
jQuery.fn.fullscreenr(FullscreenrOptions);
//Delayed redirect
function delayer(){
window.location = "../user_cp.php?action=login";
}
</script>
</head>
<?php
require 'user.inc.php';
global $user;
if(empty($_SESSION['user']))
{
if (isset ($_GET['action']))
{
$action = $_GET['action'];
switch ($action)
{
case 'login':
{
echo '<img id="bgimg" src="xxx"></img>';
echo '<div id="realBody">';
echo '<div id="login-container">';
if (isset ($_POST['submit']))
{
$canLogin = $user -> login ($_POST);
if (!$canLogin)
{
$user->form($action);
$user->display_notice($action);
}
else if ($canLogin)
{
$user->redirect();
$user->display_notice($action);
}
}
else
{
$user->form($action);
}
break;
}
case 'register':
{
echo '<img id="bgimg" src="xxx"></img>';
echo '<div id="realBody">';
echo '<div id="register-container">';
if (isset ($_POST['submit']))
{
$canRegister = $user -> register ($_POST);
if (!$canRegister)
{
$user->form($action);
$user->display_notice($action);
}
else if ($canRegister)
{
//$user->redirect();
$user->display_notice($action);
}
}
else
{
$user->form($action);
}
break;
}
}
}
else
{
echo "<br> User not logged in";
//$user->redirect();
}
echo "</form></div>";
}
else //For testing purposes this check has been removed
{
$user->display_private();
}
?>
</body>
</html>
I'm able to register, the data is created in the database and everything works like it should, I just get that error when registerign a new user... and do not know why that foreach is causing the issues. If you need more code, let me know because I'm all out of solutions. Thanks in advance for your help.
In case you have questions abotu the Message class here is the code:
message.class.php
<?php
require 'message.inc.php';
class Message
{
private $message;
public function __set ($name, $value)
{
switch ($name)
{
case 'message':
{
if (property_exists ($this, 'message'))
{
$this -> message = $value;
}
else
{
echo "<br> Member does not exist";
}
}
}
}
public function __get ($name)
{
switch ($name)
{
case 'message':
{
if (isset ($this -> message))
{
return $this -> message;
}
else
{
return NULL;
}
}
}
}
public function __construct ($message)
{
/*
* Error Codes
* 1 = Can only use Alphanumeric characters in Username
* 10 = Username too short
* 11 = Username too long
* 13 = Username Exists
* 14 = Username verified
* 20 = Password too short
* 21 = Password too long
* 22 = Passwords do not match
* 24 = Password Verified
* 30 = Email is too short
* 32 = E-mails do not match
* 33 = E-mail Exists
* 34 = E-mail Verified
* 45 = Registration Successful
* 46 = Registration Failed
* 55 = Login Successful
* 56 = Login Failed
* 67 = Empty Fields
* 9005 = Unidentified Error
* ?? = Unknown Error
*/
switch ($message)
{
case INV_USER: $this -> message = "You can only use alphanumeric characters in your username (a-z, 0-9).";
break;
case SHORT_USER: $this -> message = "Username needs to be 4 characters or longer.";
break;
case LONG_USER: $this -> message = "Username can not exceed 15 characters.";
break;
case EXISTS_USER: $this -> message = "Username already exists.";
break;
case VER_USER: $this -> message = "Username has been verified.";
break;
case SHORT_PASS: $this -> message = "Password needs to be 6 characters or longer.";
break;
case LONG_PASS: $this -> message = "Password can not exceed 30 characters.";
break;
case MATCH_PASS: $this -> message = "Passwords do not match.";
break;
case VER_PASS: $this -> message = "Password has been verified.";
break;
case SHORT_EMAIL: $this -> message = "E-mail is too short.";
break;
case MATCH_EMAIL: $this -> message = "E-mails do not match.";
break;
case EXISTS_EMAIL: $this -> message = "E-mail already exists.";
break;
case VER_EMAIL: $this -> message = "E-mail has been verified.";
break;
case LOGIN_SUCCESS: $this -> message = "Login was successful";
break;
case LOGIN_FAILED: $this -> message = "Login was unsuccessful, please check your credentials and try again.";
break;
case REG_SUCCESS: $this -> message = "Registration was successful";
break;
case REG_FAILED: $this -> message = "Registration was unseccessful, please check your credentials and try again.";
break;
case EMPTY_FIELD: $this -> message = "There are one or more empty fields, please check your credentials and try again.";
break;
case UNI_ERROR: $this -> message = "Unidentified Error";
break;
default: $this -> message = "Unknown Error";
break;
}
}
public function __destruct ()
{
echo $this -> get_message ();
}
public function get_message ()
{
return "<br> " . $this -> message;
}
}
?>
message.inc.php
<?php //define message() constants define (INV_USER, 1); define (SHORT_USER, 10); define (LONG_USER, 11); define (EXISTS_USER, 13); define (VER_USER, 14); define (SHORT_PASS, 20); define (LONG_PASS, 21); define (MATCH_PASS, 22); define (VER_PASS, 24); define (SHORT_EMAIL, 30); define (MATCH_EMAIL, 32); define (EXISTS_EMAIL, 33); define (VER_EMAIL, 34); define (REG_SUCCESS, 45); define (REG_FAILED, 46); define (LOGIN_SUCCESS, 55); define (LOGIN_FAILED, 56); define (EMPTY_FIELD, 67); define (UNI_ERROR, 9005); //define DEBUG mode define (DEBUG, true); ?>

New Topic/Question
Reply



MultiQuote






|