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');

}

</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="javascript:x();">checkavailablity</a></p>
</form>
</body>
</html>

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

$get_value=$_REQUEST['value'];
//connect to the database
$query="select count(username) as us from <table> WHERE username='$get_value'";
$res=mysql_query($query);
while($row=mysql_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>";

}


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


ronverdonk
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:
[PHP]<?php
if (isset($_POST['_submit'])) {
$get_value=$_POST['t'];
//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>";
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:
Jul 21 '06 #2

Post your reply

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