To create a checkavailabilty link in php for checking username on a hyperlink click

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sankviju
    New Member
    • Jun 2006
    • 3

    To create a checkavailabilty link in php for checking username on a hyperlink click

    Here i created a javascript+php code by which u can create a check available link that u will usually see in many websites.Withou t submitting the whole form just u can check wther a username exist in the database or not
    =============== =============== =============== ====-=====
    1:filenames: index.php

    write a javascript fn like this in the head tag
    <script language="javas cript">
    function x()
    {
    var y=document.form 1.t.value;
    open("newtest.p hp?value="+y,wi dth='10', height='10');

    }

    </script>
    <body>
    <form id="form1" name="form1" method="get" action="newtext .php?value=y;">
    <p>
    <input name="t" type="text" id="t" />
    <a href="#" onclick="javasc ript:x();">chec kavailablity</a></p>
    </form>
    </body>
    </html>

    =============== =============== =============== =====
    In 2 nd Page(newtest.ph p) you can access this value like :

    $get_value=$_RE QUEST['value'];
    //connect to the database
    $query="select count(username) as us from <table> WHERE username='$get_ value'";
    $res=mysql_quer y($query);
    while($row=mysq l_fetch_array($ res))
    {
    if($rows['us']>=1)
    {
    echo "<div align='center'> <font color='red'><b> Sorry username exist</b></font></div>";
    }
    else
    {
    echo "<div align='center'> <font color='blue'><b >You can use this username</b></font></div>";

    }


    }
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    I doesn't make a lot of difference. You still submit the variables. So, to pack it into one smaller routine and without messing without JavaScript, I give you the following code:
    [PHP]<?php
    if (isset($_POST['_submit'])) {
    $get_value=$_PO ST['t'];
    //connect to the database
    $res=mysql_quer y("select * from <table> WHERE user='$get_valu e'");
    if (mysql_num_rows ($res)>0)
    echo "<div align='center'> <font color='red'><b> Sorry, username already exists, choose another one</b></font></div>";
    else
    echo "<div align='center'> <font color='blue'><b >You can use this username</b></font></div>";
    }
    ?>
    <body>
    <form method="POST" action="testit. php">
    <p><center>
    Type your text <input name="t" type="text" />
    <input type="submit" value="search" />
    <input type="hidden" name="_submit" value="1" />
    </center>
    </form>
    </body>
    </html>[/PHP]

    Ronald :cool:

    Comment

    Working...