Add 'Tag' To Error Message?

Hi,

I have a code which returns an error message however I am trying add a ‘tag’ to it.

$query = mysql_query("SELECT * FROM users WHERE email = '". $registerEmail ."' OR email = '". $email ."'");

if (mysql_num_rows($query) > 0)
{
     echo 'Email Address is Already In Use.  Please Retrieve Your Password.';
}	  		
	

I am trying to add a ‘tag’ so that I can place the error message in a certain place on the page.

		$query = mysql_query("SELECT * FROM users WHERE email = '". $registerEmail ."' OR email = '". $email ."'");

if (mysql_num_rows($query) > 0)
{
          $success['emailduplicate'] = 'Email Address is Already In Use.  Please Retrieve Your Password.';
}	

Im trying to add a tag “emailduplicate” so that I can echo the error message in a DIV.

		  	<div class="registerinputerrors">
			<?php if($errors['emailduplicate']) print '<div class="invalid">' . $errors['emailduplicate'] . '</div>'; ?>
             </div>
				  

Can anyone advise how I do this?

I’m not sure from your example what you’re trying to do. Is it:

A) Replace all or part of the actual message?
B) Change the display based on message content?

Hi,

The top piece of code echoes the error message in the very top left of the page. I am trying to move it to a specific place on the page. I am trying to add a ‘tag’ called “emailduplicate”.

So I can display the error message where ever I place the following code:

            <?php if($errors['emailduplicate']) print '<div class="invalid">' . $errors['emailduplicate'] . '</div>'; ?>

It seems like you’re simply wanting to know how to use CSS to place the div with the class “registerinputerrors” at a specific place rather than where it appears in the html. If so, this isn’t really a coding issue. I’ll wait for your response before requesting that the thread be moved.

Lets say I have an error code and want to display the error message twice how would I do this?

Just repeat the echo statement. As long as you haven’t done anything to null the value, it’ll work.


<?php
$message = "hello world";
?>

<HTML>
<HEAD>
<TITLE><?php echo $message; ?><TITLE>
</HEAD>
<BODY>

<b><?php echo $message; ?></b>

<i><?php echo $message; ?></i>


</BODY>
</HTML>

If this is not what you meant, please clarify.

Thanks, but I dont know how to apply ‘Email Address is Already In Use. Please Retrieve Your Password.’ to $message.

$query = mysql_query("SELECT * FROM users WHERE email = '". $registerEmail ."' OR email = '". $email ."'");

if (mysql_num_rows($query) > 0)
{
     echo 'Email Address is Already In Use.  Please Retrieve Your Password.';
}
$query = mysql_query("SELECT * FROM users WHERE email = '". $registerEmail ."' OR email = '". $email ."'"); 
$message = null;
if (mysql_num_rows($query) > 0) 
{ 
$message = 'Email Address is Already In Use.  Please Retrieve Your Password.'; 
}

then



<p><?php if  (!is_null($message)) echo $message; ?></p>


Brilliant, cheers dude. That works fine.

The problem I have now is that the email is still submitted to the database. Is it possible to stop the email from being submitted once it reads that the email address is already in the database?

Put the call to insert inside an ‘else’ construct.

http://php.net/manual/en/control-structures.elseif.php