SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Add 'Tag' To Error Message?

    Hi,

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

    Code:
    $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.

    Code:
    		$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.

    Code:
    		  	<div class="registerinputerrors">
    			<?php if($errors['emailduplicate']) print '<div class="invalid">' . $errors['emailduplicate'] . '</div>'; ?> 
                 </div>
    Can anyone advise how I do this?

  2. #2
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    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?

  3. #3
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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:


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

  4. #4
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Lets say I have an error code and want to display the error message twice how would I do this?

  6. #6
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Just repeat the echo statement. As long as you haven't done anything to null the value, it'll work.

    PHP Code:
    <?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.

  7. #7
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but I dont know how to apply 'Email Address is Already In Use. Please Retrieve Your Password.' to $message.

    HTML Code:
    $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.'; 
    }

  8. #8
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    Thanks, but I dont know how to apply 'Email Address is Already In Use. Please Retrieve Your Password.' to $message.

    HTML Code:
    $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.'; 
    }


    PHP Code:
    $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

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

  9. #9
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    730
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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?

  10. #10
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Put the call to insert inside an 'else' construct.

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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •