SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript Popup in Echo?

    I have a register code, and if the username is taken, currently, it takes them to another page to say the username is taken.

    Is it possible to do a javascript popup box if the username is taken? here is register.php

    PHP Code:
    <?php
    if($_POST["username"] && $_POST["password"] && $_POST["password2"] )
    {
    $username $_POST["username"];
    $password $_POST["password"];
    $password2 $_POST["password2"];

        if(
    $password==$password2)
        {
        
    $password md5($password);
        
    $DBservername="localhost";
        
    $DBusername="******";
        
    $DBpassword="******";
       
    $conn =  mysql_connect($DBservername,$DBusername,$DBpassword)or die(mysql_error());
        
    mysql_select_db("gogreen",$conn);
        
        
    $dbunames mysql_query("SELECT * FROM `members` WHERE username='$username'");
        if(
    mysql_num_rows($dbunames) > ) {
            echo 
    "Username Taken!";    

        } else {
        
        
    $sql="INSERT INTO `members` (username,password)values('$username','$password')";
        
    $result=mysql_query($sql,$conn) or die(mysql_error());        
        print 
    "<h1>you have registered sucessfully</h1>";
     
        
    header("Location: ../index.php");
        }
        }
        else print 
    "Passwords doesnt match";
    }



    ?>

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of

    PHP Code:
    echo "Username Taken!"
    PHP Code:
    echo <<<EOF
    <script>
    alert('Username Taken!')
    </script>
    EOF; 

  3. #3
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Above would work, also put exit after your header:

    PHP Code:
    header("Location: ../index.php");
    exit(); 

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That actually worked perfect. Now, after it pops up with that, how would I re-direct back to index so they can type in another username? Header wont work for me. ;[
    Is this possible?

  5. #5
    Non-Member
    Join Date
    Jan 2011
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by boboreo View Post
    Is it possible to do a javascript popup box if the username is taken?
    And if a visitor comes along with javascript turned off in their browser, how will you let them know a username is taken?

  6. #6
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    They better turn that javascript on!

  7. #7
    Non-Member
    Join Date
    Jan 2011
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't force people to turn javascript on. If you try to, you're more likely to lose them.


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
  •