Tuesday 9 July 2013

Registration Form in PHP using Java Script Validations

// Registration Form in PHP using Java Script Validations

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<style type="text/css">
.regfirm {
font-size: 20px;
color: #0033FF;
}
.star {
color: #F00;
}
</style></head>

<body>
 <script type="text/javascript">
function uservalid()
{
var name=document.form1.name.value;
var namexp=/^[a-zA-Z ]*$/;
var uid=document.form1.uid.value;
var password=document.form1.pass.value;
var pexpnum=/^(?=.*[0-9])/;
var pexpcap=/^(?=.*[A-Z])/;
var pexpsm=/^(?=.*[a-z])/;
var cpass=document.form1.cpass.value;
var dob=document.form1.dob.value;
var phno=document.form1.mobile.value;
var phexp=/^[0-9]+$/;
var email=document.form1.email.value;
var atpos=email.indexOf("@");
var dotpos=email.lastIndexOf(".");
var address=document.form1.addr.value;
if(name=="")
{
alert("Please Enter Your Name");
document.form1.name.focus();
return false;
}
else if(!name.match(namexp))
{
alert("Please Enter Valid Name");
document.form1.name.focus();
return false;
}
else if(uid=="")
{
alert("Please Enter User Id");
document.form1.uid.focus();
return false;
}
else if(uid.length<5)
{
alert("User Id Minimum 5 letters");
document.form1.uid.focus();
return false;
}

else if(password=="")
{
alert("Please Enter Password");
document.form1.pass.focus();
return false;
}
else if(password.length<6)
{
alert("Password must be more than 6 letters");
document.form1.pass.focus();
return false;
}
else if(!password.match(pexpnum))
{
alert("Password contain atleast one Number");
document.form1.pass.focus();
return false;
}
else if(!password.match(pexpcap))
{
alert("Password contain atleast one Capital letter");
document.form1.pass.focus();
return false;
}
else if(!password.match(pexpsm))
{
alert("Password contain atleast one Small letter");
document.form1.pass.focus();
return false;
}
else if(cpass=="")
{
alert("Please Enter Conform Password");
document.form1.cpass.focus();
return false;
}
else if(password!=cpass)
{
alert("Password and Conform password must be same");
document.form1.cpass.focus();
return false;
}
else if(dob=="")
{
alert("Please Enter Date Of Birth");
document.form1.dob.focus();
return false;
}
else if(phno=="")
{
alert("Please Enter Phone no");
document.form1.mobile.focus();
return false;
}
else if(!phno.match(phexp))
{
alert("Enter Valid Phone no");
document.form1.mobile.focus();
return false;
}
else if(phno.length!=10)
{
alert("Enter 10 digit Phone no");
document.form1.mobile.focus();
return false;
}
else if(email=="")
{
alert("Please Enter Email Id");
document.form1.email.focus();
return false;
}
else if(atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length)
{
alert("Enter Valid Email Id EX: abc@d.com");
document.form1.email.focus();
return false;
}
   else if ( ( document.form1.gender[0].checked == false ) && ( document.form1.gender[1].checked == false ) )
   {
        alert ( "Please choose Your Gender" );
        document.form1.gender[0].focus();
        return false;
    }
else if(address=="")
{
alert("Please Enter Your Full Address");
document.form1.addr.focus();
return false;
}


}
</script>

<table width="562" border="0" align="center" vspace="0px">
  <tr>
    <td>
    <form name="form1" id="form1" method="post" action="" onsubmit="return uservalid()"><table width="500" border="0" align="center">
      <tr>
        <td colspan="2" align="center"><span class="regfirm">Registraion Form</span></td>
      </tr>
      <tr>
        <td width="135">Name <label class="star">*</label></td>
        <td width="234" height="35"><input type="text" name="name" id="name" placeholder="Enter Your Full Name" /></td>
      </tr>
      <tr>
        <td>User Id <label class="star">*</label></td>
        <td height="35"><input type="text" name="uid" id="uid" placeholder="Enter Your User Id" /></td>
        </tr>
      <tr>
        <td>Password <label class="star">*</label></td>
        <td height="35"><input type="password" name="pass" id="pass" placeholder="Create New Password" /></td>
        </tr>
      <tr>
        <td>Conform Password <label class="star">*</label></td>
        <td height="35"><input type="password" name="cpass" id="cpass" placeholder="Enter Same Password " /></td>
        </tr>
      <tr>
        <td>Date Of Birth <label class="star">*</label></td>
        <td height="35"><input type="date" name="dob" id="dob" /></td>
        </tr>
      <tr>
        <td>Contact Number <label class="star">*</label></td>
        <td height="35"><input type="text" name="mobile" id="mobile" placeholder="Enter Your Contact Number" /></td>
        </tr>
      <tr>
        <td>Email Id <label class="star">*</label></td>
        <td height="35"><input type="text" name="email" id="email" placeholder="Enter Your Email Id" /></td>
        </tr>
      <tr>
        <td>Gender <label class="star">*</label></td>
        <td><p>
          <label>
            <input type="radio" name="gender" value="male" />
            Male</label>
          <br />
          <label>
            <input type="radio" name="gender" value="female" />
            Female</label>
          <br />
        </p></td>
        </tr>
      <tr>
        <td>Address <label class="star">*</label></td>
        <td><textarea name="addr" id="addr" cols="25" rows="3" placeholder="Enter Your Full Address" style="resize:none"></textarea></td>
        </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
      <tr>
        <td colspan="2"><table width="358" border="0">
          <tr>
            <td width="104">&nbsp;</td>
            <td width="95"><input type="submit" name="submit" id="submit" value="Submit" /></td>
            <td width="103"><input type="reset" name="reset" id="reset" value="Reset" /></td>
            <td width="38">&nbsp;</td>
            </tr>
          </table></td>
      </tr>
      </table>
    </form></td>
  </tr>
  <tr>
  <td height="30" align="center" bgcolor="#3850AF">Copy Rights&copy;Narsi Reddy 2013</td>
  </tr>
</table>
</body>
</html>

Login Page In PHP Mysql using java script

// Login Page In PHP Mysql using java script

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
function uservalid()
{
var name = document.form1.username.value;
if(name =="")
{
alert("Please Enter Name");
document.form1.focus();
return false;
}
}</script>
<?php
if(isset($_POST['sub']))
{
$username=$_POST['username'];
$password=$_POST['password'];
$con=mysql_connect("localhost", "root", "")or die("cannot connect");
  $db=mysql_select_db("bnr");
  $sql="SELECT * FROM login
WHERE name='$username' and password='$password'";
  $query=mysql_query("$sql");
  $count=mysql_num_rows($query);
   
    if($count!=0)
{
  echo "Login Success";
}
else
echo "<font color='#FF0000'>invalid</font>";
}
?>

</head>
<body>

<form action="" method="post" id="form1" name="form1" enctype="multipart/form-data" onsubmit="return uservalid()">
username:<input type="text" name="username" id="username" />
<br />
password:<input type="password" name="password" id="password" />
<br />
<input type="submit" value="login" name="sub" />
</form>
</body>
</html>

Login Page In PHP Mysql using sessions

// Login Page In PHP Mysql using sessions

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?php
session_start();
if(isset($_POST['sub']))
{
$username=$_POST['username'];
$password=$_POST['password'];
$con=mysql_connect("localhost", "root", "")or die("cannot connect");
  $db=mysql_select_db("bnr");
  $sql="SELECT * FROM login
WHERE name='$username' and password='$password'";
  $query=mysql_query("$sql");
  $count=mysql_num_rows($query);
   
    if($count!=0)
{
//session_register("name");
     // session_register("password");
 

$_SESSION['out']=true;
echo "Login Success";

}
else
echo "<font color='#FF0000'>invalid</font>";
}
?>

</head>
<body>

<form action="" method="post" id="form1" name="form1" enctype="multipart/form-data" >
username:<input type="text" name="username" id="username" />
<br />
password:<input type="password" name="password" id="password" />
<br />
<input type="submit" value="login" name="sub" />
</form>
</body>
</html>

Login Page In PHP Mysql using sessions and java script

// Login Page In PHP Mysql using sessions and java script

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
function uservalid()
{
var name = document.form1.username.value;
if(name =="")
{
alert("Please Enter Name");
document.form1.focus();
return false;
}
}</script>
<?php
session_start();
if(isset($_POST['sub']))
{
$username=$_POST['username'];
$password=$_POST['password'];
$con=mysql_connect("localhost", "root", "")or die("cannot connect");
  $db=mysql_select_db("bnr");
  $sql="SELECT * FROM login
WHERE name='$username' and password='$password'";
  $query=mysql_query("$sql");
  $count=mysql_num_rows($query);
   
    if($count!=0)
{
//session_register("name");
     // session_register("password");


$_SESSION['out']=true;
echo "Login Success";

}
else
echo "<font color='#FF0000'>invalid</font>";
}
?>

</head>
<body>

<form action="" method="post" id="form1" name="form1" enctype="multipart/form-data" onsubmit="return uservalid()">
username:<input type="text" name="username" id="username" />
<br />
password:<input type="password" name="password" id="password" />
<br />
<input type="submit" value="login" name="sub" />
</form>
</body>
</html>

Get data From data base in php mysql

// Get data From data base in php mysql

<?php
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("bnr");
$sql="select *from reg";
$query=mysql_query($sql);
while($row = mysql_fetch_array($query))
  {
  $username=$row['username'];
  echo  $row['username'] 
  echo  $row['name'] 
  echo  $row['password'] 
  echo  $row['emp_id'] 
  echo  $row['phone_no'] 
  echo  $row['email_id'] 
  echo  $row['address'] 
  }
mysql_close($con);
?>
<html>
<head></head>
<body>
</body>
</html>

Get data from Mysql DataBase in PHP (Display in Table)

// Get data from Mysql DataBase in PHP (Display in Table)

<?php
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("bnr");
$sql="select *from reg";
$query=mysql_query($sql);

 echo "<table border='1'>
<tr>
<th>User Name</th>
<th>Name</th>
<th>password</th>
<th>Emp ID</th>
<th>Phone No</th>
<th>Email ID</th>
<th>Address</th>
</tr>";

while($row = mysql_fetch_array($query))
  {
 $username=$row['username'];
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['password'] . "</td>";
  echo "<td>" . $row['emp_id'] . "</td>";
  echo "<td>" . $row['phone_no'] . "</td>";
  echo "<td>" . $row['email_id'] . "</td>";
  echo "<td>" . $row['address'] . "</td>";
  echo "</tr>";
  }

mysql_close($con);




?>
</table>
<html>
<head></head>
<body>
</body>
</html>

Monday 8 July 2013

Insert to DataBase in php using mysql

//index.php 

// Insert to DataBase in php using mysql

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="regcode.php" >
 <table width="299" border="0" align="center">
      <tr>
        <td colspan="2" align="center"><font color="red" size="+1">Employee Registration Form</font></td>
      </tr>
      <tr>
        <td width="143" align="left">&nbsp;</td>
        <td width="264" align="left">&nbsp;</td>
      </tr>
      <tr>
        <td align="left">Name</td>
        <td align="left"><label for="name"></label>
        <input name="name" type="text" id="name" size="25" placeholder="Enter ur Name" /></td>
      </tr>
       <tr>
        <td align="left">Phone No</td>
        <td align="left"><label for="phone_no"></label>
        <input name="phone_no" type="text" id="phone_no" size="25" maxlength="10" placeholder="Enter Phone Number" /></td>
      </tr>
      <tr>
        <td align="left">Email Id</td>
        <td align="left"><label for="email_id"></label>
        <input name="email_id" type="text" id="email_id" size="25" /></td>
      </tr>
      <tr>
        <td align="left">User Name</td>
        <td align="left"><label for="username"></label>
        <input name="username" type="text" id="username" onKeyUp="loadXMLDoc(this.value)" size="25"/></td>
      </tr>
      <tr>
        <td align="left">Password</td>
        <td align="left"><label for="password"></label>
        <input name="password" type="password" id="password" size="25" /></td>
      </tr>
      <tr>
        <td align="right"><input type="submit" name="submit" id="submit" value="Submit" /></td>
        <td align="center"><input type="reset" name="reset" id="reset" value="Reset" /></td>
      </tr>
    </table>
    <div align="center"></div>
</form>
</form>
</body>
</html>


Insert, Edit, Delete in php mysql

// index.php
 
<?php
if(isset($_POST['add']))
{
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("bnr");
$sql="insert into idauto values('$id','$name','$email')";
$query=mysql_query($sql);
if($query==true)
{
    echo "Registered Successfull";
}
else
{
    echo "fail";
}}
/*$result=mysql_query("select id from idauto where name='$name' and email='$email'");
while($row = mysql_fetch_array($result))
{
    echo "<br/>Your Id Is:"." ".$row['id'];
}*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<form id="form1" name="form1" method="post">
  <table width="745" border="0" align="center">
   
   
   
    <tr>
      <td>Id</td>
      <td><label for="id"></label>
      <input name="id" type="text" disabled="disabled" id="id" /></td>
    </tr>
    <tr>
      <td>Name</td>
      <td><label for="name"></label>
      <input type="text" name="name" id="name" /></td>
    </tr>
    <tr>
      <td>Email Id</td>
      <td><label for="email"></label>
      <input type="text" name="email" id="email" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="add" id="save" value="Add" />
       
      </td>
    </tr>
  
    </table>
  <table border="1" align="left">
  <?php
  $name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("bnr");
$sql="select *from idauto";
$query=mysql_query($sql);

while($test = mysql_fetch_array($query))
            {
                $id = $test['id'];   
                echo "<tr>";   
                echo"<td><font color='black'>" .$test['id']."</font></td>";
                echo"<td><font color='black'>" .$test['name']."</font></td>";
                echo"<td><font color='black'>". $test['email']. "</font></td>";
                   
                echo"<td> <a href ='update.php?id=$id'>Edit</a>";
                echo"<td> <a href ='delete.php?id=$id'><center>Delete</center></a>";
                                   
                echo "</tr>";
            }
            mysql_close($con);

?>
  </table>
</form>
</body>
</html>

//savecode.php
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
    <?php
//$id=$_REQUEST['id'];
$name=$_REQUEST['name'];
$email=$_REQUEST['email'];
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("bnr");
$sql="insert into idauto values('$id','$name','$email')";
$query=mysql_query($sql);
if($query==true)
{
    echo "Registered Successfull";
}
else
{
    echo "fail";
}
$result=mysql_query("select id from idauto where name='$name' and email='$email'");
while($row = mysql_fetch_array($result))
{
    echo "<br/>Your Id Is:"." ".$row['id'];
}
?>
</body>
</html>
 // update.php

<?php
$con=mysql_connect("localhost","root","");
$db=mysql_select_db("bnr");
$id =$_REQUEST['id'];

$result = mysql_query("SELECT * FROM idauto WHERE id  = '$id'");
$test = mysql_fetch_array($result);
if (!$result)
        {
        die("Error: Data not found..");
        }
                $name=$test['name'] ;
                $email= $test['email'] ;                   
               
if(isset($_POST['update']))
{   
    $name_save = $_POST['name'];
    $email_save = $_POST['email'];

    mysql_query("UPDATE idauto SET name ='$name_save', email ='$email_save' WHERE id = '$id'")
                or die(mysql_error());
    echo "Saved!";
   
    header("Location: index.php");           
}
mysql_close($con);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <table width="274" height="91" border="1" align="center">
    <tr>
      <td width="72">Id</td>
      <td width="186"><label for="id"></label>
      <input name="id" type="text" disabled="disabled" id="id" value="<?php echo $id ?>"/></td>
    </tr>
    <tr>
      <td>Name</td>
      <td><label for="name"></label>
      <input type="text" name="name" id="name" value="<?php echo $name ?>" /></td>
    </tr>
    <tr>
      <td>Email Id`</td>
      <td><label for="email"></label>
      <input type="text" name="email" id="email" value="<?php echo $email ?>"/></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="update" id="update" value="Submit" /></td>
    </tr>
  </table>
</form>
</body>
</html>

Thursday 4 July 2013

Syntax of Data Base connection using mysql in php



<?php
$con=mysql_connect("servername","username","password");
// ex: $con=mysql_connect("localhost","root","");
$db=mysql_select_db("database name");
$sql="sql query";
$query=mysql_query($sql);

?>