5 Replies - 240 Views - Last Post: 24 April 2014 - 03:37 PM Rate Topic: -----

#1 UnknownCoder  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 137
  • Joined: 22-February 09

Message function not working

Posted 22 April 2014 - 10:59 AM

Hi,

I've been trying to get my messages function to work but to no avail.

Here's the function I've come up with:

// message
function messages() {
	$text = '';
	$message = array(
		'error' => '',
		'success' => ''
	);
	if($message['error'] != ''){
		$text = '<div class="message animated fadeInDown">'.$message['error'].'</div>';
		$message['error'] = '';
	}
	if($message['success'] != ''){
		$text = '<div class="message animated fadeInDown">'.$message['success'].'</div>';
		$message['success'] = '';
	}
	echo "$text";
}



Then I should be able to call it in my pages like so:

<?php echo messages();?>



If anyone could help me with this it would be much appreciated, thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Message function not working

#2 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 618
  • View blog
  • Posts: 2,766
  • Joined: 03-December 12

Re: Message function not working

Posted 22 April 2014 - 11:30 AM

What's wrong with it? What does it currently do?

This post has been edited by astonecipher: 22 April 2014 - 11:30 AM

Was This Post Helpful? 0
  • +
  • -

#3 UnknownCoder  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 137
  • Joined: 22-February 09

Re: Message function not working

Posted 22 April 2014 - 02:01 PM

View Postastonecipher, on 22 April 2014 - 07:30 PM, said:

What's wrong with it? What does it currently do?


I want to be able to display an error or success message when something happens i.e login a user.

At the moment it fails to display an error message when I set it and echo it out:

$message['error'] = 'Sorry, wrong password.';

echo $messages();



Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#4 ArtificialSoldier  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 359
  • View blog
  • Posts: 1,308
  • Joined: 15-January 14

Re: Message function not working

Posted 22 April 2014 - 02:08 PM

echo $messages();


That is not going to work with the $ there, you're telling PHP to execute a function whose name is saved in the variable $messages. Also, your messages function does not return a value, it just prints.

There's a bigger problem though.

	$text = '';
	$message = array(
		'error' => '',
		'success' => ''
	);
	if($message['error'] != ''){
		...
	}
	if($message['success'] != ''){
		...
	}


You set $message to be an array where both elements are empty, and then you check to see if the elements are not empty. Of course they are empty, you just set them to be empty. So neither of those if statements succeed, and $text never gets set to anything else.
Was This Post Helpful? 1
  • +
  • -

#5 UnknownCoder  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 137
  • Joined: 22-February 09

Re: Message function not working

Posted 22 April 2014 - 02:32 PM

Thanks for getting back to me. I will try a different approach I guess.

This post has been edited by andrewsw: 22 April 2014 - 02:35 PM
Reason for edit:: Removed previous quote

Was This Post Helpful? 0
  • +
  • -

#6 Oliverkahn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 24-April 14

Re: Message function not working

Posted 24 April 2014 - 03:37 PM

01 // message
02 function messages() {
03 $text = '' ;
04 $message = array (
05 "error"=> '',
06 "success"=> ''
07 );
08 if($message ['error' ] != ''){
09 $text = '<div class="message
animated fadeInDown">' .$message
['error' ].'</div>' ;
10 $message ['error' ] = '';
11 }
12 if($message ['success' ] != ''){
13 $text = '<div class="message
animated fadeInDown">' .$message
['success' ].'</div>' ;
14 $message ['success' ] = '';
15 }
16 echo "$text" ;
17 } 



you need to assign values to those variable
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1