Monday, 8 June 2015

checked user name with javascript

username : {
required : true,
remote : 'remote_check_uname.php'
},

===================
<?php
include('connection.php');
//header('Content-type: application/json');
$uname = $_REQUEST['username'];

$qurey=mysql_query("select `uname` from books_customer where uname= '$uname'");
if (mysql_num_rows($qurey) == '0') {
    $output = 'true';
}
else {
    $output = 'false';
}
echo $output;
?>

dropdown country state

 <section class="col col-6">
<label class="select">
                                                 <span style="color:red;">*</span>
<select name="country" class="select2" onChange="getState(this.value);">
<option value="">Country</option>
                                                        <?php

$coun=mysql_query("select * from country");
while($rows=mysql_fetch_array($coun))
{

?>
<option value="<?php echo $rows['c_id']; ?>"><?php echo $rows[1]; ?></option>
<?php

}
?>

</select>  </label>
</section>
                                            <section class="col col-6">
                                             <span style="color:red;">*</span>
<label class="select">
<select name="state" class="select2" id="state-list">
<option value="">State</option>

</select>  </label>
</section>

<!-- country -->

<script>
function getState(val) {
$.ajax({
type: "POST",
url: "get_state.php",
data:'c_id='+val,
success: function(data){
$("#state-list").html(data);
}
});
}

function selectCountry(val) {
$("#search-box").val(val);
$("#suggesstion-box").hide();
}
</script>

<!-- end Country -->

===============
get_state.php
==========================

<?php
include("connection.php");

$id=$_POST['c_id'];

if($id == 76) {
$id1=76;
}
else
{
$id1=0;
}
$query ="SELECT * FROM `tbl_state` WHERE c_id = '$id1'";

$results = mysql_query($query);
?>
<option value="">Select State</option>

<?php
while($row=mysql_fetch_array($results))
{
?>
<option value="<?php echo $row["state_id"]; ?>"><?php echo $row["state_name"]; ?></option>
<?php
                    }
?>


javascript

letters only and phone number
=====================
<script>
jQuery.validator.addMethod("lettersonly", function(value, element) {
return this.optional(element) || /^[a-z. ]+$/i.test(value);
}, "Please enter only character");

jQuery.validator.addMethod("phoneno", function(phone_number, element) {
     phone_number = phone_number.replace(/\s+/g, "");
     return this.optional(element) || phone_number.length > 9 &&
     phone_number.match(/^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/);
  }, "<br />Please specify a valid phone number");
</script>
===============
number exple 22.22
==================
<script>
$('.number').keypress(function (event) {
    if ((event.which != 46 || $(this).val().indexOf('.') != -1) && (event.which < 48 || event.which > 57)) {
        event.preventDefault();
    }
    var text = $(this).val();
    if ((text.indexOf('.') != -1) && (text.substring(text.indexOf('.')).length > 2)) {
        event.preventDefault();
    }
});
</script>

Login with session

index.php
==============
<?php
session_start();
mysql_connect("localhost","root","root");
mysql_select_db("mitul");
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>

<body>
<form name="f1" method="post">
<table border="1">
 
     <tr>
      <td>Uname</td>
        <td><input type="text" name="txtname" ></td>
   
     </tr>
     <tr>
       <td>Pass</td>
       <td><input type="password" name="txtpass"></td>
   
     </tr>
   <tr>
     <td colspan="2"><input type="submit" value="log" name="btnlog"></td>
   </tr>
 


</table>

</form>

<?php
  if(isset($_POST['btnlog']))
  {
 
  $txtuname=$_POST['txtname'];
$txtpass=$_POST['txtpass'];

$sql="select * from exam  where uname='$txtuname' and pass='$txtpass'";
$sqlexc=mysql_query($sql);
$num=mysql_num_rows($sqlexc);
$fetch=mysql_fetch_array($sqlexc);
$id=$fetch['id'];



if($num > 0)
{
$_SESSION['hello']=$id;
echo "<script>window.location='home.php';</script>";

}
else
{
echo "wrong";
}
 
   }

?>
</body>
</html>
====================
home.php
====================
<?php
session_start();

mysql_connect("localhost:3306","root","root");
mysql_select_db("smartadmin");

if(!$_SESSION['hello'])
{
  echo '<script>window.location="index.php";</script>';

 }


?>

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>

<body>
<?php
 $id=$_SESSION['hello'];

$sql="select * from exam where id='$id'";
$sqlexcu=mysql_query($sql);
$fetch=mysql_fetch_array($sqlexcu);
$name=$fetch['uname'];
echo "uname&nbsp;".$name;
 ?>
 <a href="logout.php" > logout</a>
<h5><?php echo $id; exit; ?></h5>
</body>
</html>
=============
logout.php
===============
<?php
session_start();
session_destroy();
echo '<script>window.location="index.php";</script>';


 ?>