By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,094 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

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

P: 3
Here i created a javascript+php code by which u can create a check available link that u will usually see in many websites.Without 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="javascript">
function x()
var y=document.form1.t.value;
open("newtest.php?value="+y,width='10', height='10');


<form id="form1" name="form1" method="get" action="newtext.php?value=y;">
<input name="t" type="text" id="t" />
<a href="#" onclick="javascript:x();">checkavailablity</a></p>

In 2 nd Page(newtest.php) you can access this value like :

//connect to the database
$query="select count(username) as us from <table> WHERE username='$get_value'";
echo "<div align='center'><font color='red'><b>Sorry username exist</b></font></div>";
echo "<div align='center'><font color='blue'><b>You can use this username</b></font></div>";


Jun 28 '06 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 4,258
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:
if (isset($_POST['_submit'])) {
//connect to the database
$res=mysql_query("select * from <table> WHERE user='$get_value'");
if (mysql_num_rows($res)>0)
echo "<div align='center'><font color='red'><b>Sorry, username already exists, choose another one</b></font></div>";
echo "<div align='center'><font color='blue'><b>You can use this username</b></font></div>";
<form method="POST" action="testit.php">
Type your text <input name="t" type="text" />
<input type="submit" value="search" />
<input type="hidden" name="_submit" value="1" />

Ronald :cool:
Jul 21 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.