Update Query in Ajax
form.php:
script.php:
<?php
include('conn.php');
if(isset($_GET['id2']))
{
$id1=$_GET['id2'];
session_start();
$_SESSION['id1']=$id1;
$select2 = mysql_query("SELECT * from member where fid='$id1' ");
$i=1;
while($row1 = mysql_fetch_array($select2))
{
$fid=$row1['fid'];
$memberslist=$row1['memberslist'];
?>
<p style="text-align:center; font-size:18px;">Members:<span id="txtHint2"><?php echo $memberslist;?></span></p>
<form action="" name="form1"> <tr ><td >
<select name="members" onchange="showCustomer2(this.value">
<option value="">Select</option> <option value="platinum" >Platinum</option> <option value="gold" >Gold</option> <option value="diamond" >Diamond</option> <option value="economical" >Economical</option> <option value="freelisting" >Freelisting</option> </select></td></tr><br>
script.php:
<script type="text/javascript">
function showCustomer2(str2)
{
// alert("hi");
var xmlhttp;
if (str2=="")
{
document.getElementById("txtHint2").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint2").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","member.php?q="+str2,true);
xmlhttp.send();
}
</script>
member.php:
<?php
include("conn.php");
session_start();
$id3=$_SESSION['id1'];
if(isset($_GET['q']))
{
$id1=$_GET['q'];
$update=mysql_query("update member set memberslist='$id1' where fid='$id3'");
$select2 = mysql_query("SELECT * from member where fid='$id3' ");
$i=1;
while($row1 = mysql_fetch_array($select2))
{
echo $row1['memberslist'];
} }
?>
Username Validate using Ajax&Jquery
Download:jquey.min.js
index.php:
index.php:
<html> <style> .error{color: #FF0000;font-size:14px;} .success{color: #33CC00; font-size:14px;} #whole{ border:1px solid #F00; width:34%; margin:10%;padding:12px; margin-top:100px; background-color:#000; color:#FFF;} </style> <script src="jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> function checkUserName(usercheck) { $('#usercheck').html('<img src="images/ajax-loader.gif" />'); $.post("checkuser.php", {user_name: usercheck} , function(data) { if (data != '' || data != undefined || data != null) { $('#usercheck').html(data); } }); } </script> </head> <body> <div style="width:38%; margin:10%;padding:12px; margin-top:100px; background-color:#000; color:#FFF;"> <div style="padding:20px 0px 10px 10px;"> Username : <input type="text" name="username" id="username" onblur="checkUserName(this.value)" /> <span id="usercheck" style="padding-left:10px; ; vertical-align: middle;"></span> </div> <div style="padding:15px 0px 20px 10px;"> Password : <input type="password" name="pwd" /> </div> </div> </body> </html>checkuser.php:
<?php $arr_user=array("itechroom", "trialuser"); $username=$_POST['user_name']; if(in_array($username,$arr_user)) {echo '<span class="error">Username already exists.</span>';exit;} else if(strlen($username) < 6 || strlen($username) > 15){echo '<span class="error">Username must be 6 to 15 characters</span>';} else if (preg_match("/^[a-zA-Z1-9]+$/", $username)) { echo '<span class="success">Username is available.</span>'; } else { echo '<span class="error">Use alphanumeric characters only.</span>'; } ?>
No comments:
Post a Comment