Wednesday 11 September 2013

Enable or Disable Text field when check the check box in php

//Enable or Disable Text field when check the check box in php

<html>
<head>
<title>bnr</title>
<script language="JavaScript">
<!--

function enable_text(status)
{
status=!status;
document.f1.other_text.disabled = status;
}
//-->
</script>
</head>
<body onload=enable_text(false);>

<form name=f1 method=post>
<input type="checkbox" name=others onClick="enable_text(this.checked)" >Others
<input type=text name=other_text>
</form>

</body>
</html>

Enable and Disable submit button when click on radio button

// Enable and Disable submit button when click on radio button



<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="">
  <p>
    <label>
      <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_0" onclick="form1.b1.disabled=false" />
      yes</label>
    <br />
    <label>
      <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_1" onclick="form1.b1.disabled=true" />
      no</label>
  </p>
  <p>
    <input type="submit" name="b1" id="b1" value="Submit"
    disabled="disabled" />
  </p>

</form>
</body>
</html>

Display in Drop down list from mysql database in php

//Display in Drop down list from mysql database in php 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('bnr');

$sql = "SELECT name FROM reg";
$result = mysql_query($sql);

echo "<select name='name'>";
while ($row = mysql_fetch_array($result)) {
    echo "<option value='" . $row['name'] ."'>" . $row['name'] ."</option>";
}
echo "</select>";

?>
</body>
</html>

favicon image or title image for html page

//favicon image or title image for html page...

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>BNR</title>

<link rel="icon"
 type="image/jpg"
 href="images.jpg" />

</head>

Monday 2 September 2013

display image in registration form

//Display Image in Registration Form

//image_form.php

<html>
<body>
<fieldset>
<legend>Customer Details</legend>
<form action="action.php" enctype="multipart/form-data"
method="post">
<table>
<tr>
<td><label>Name:</label></td>
<td><input name="name" type="text" /></td>
</tr>
<tr>
<td><label>Phone No:</label></td>
<td><input name="phone" type="text" id="phone" /></td>
</tr>
<tr>
<td><label>Email Id:</label></td>
<td><input name="email" type="text" id="email" /></td>
</tr>
<tr>
<td><label>Address:</label></td>
<td><input name="address" type="text" id="address" /></td>
</tr>
<tr>
<td><label>Country:</label></td>
<td><input name="con" type="text" id="con" /></td>
</tr>
<tr>
<td><label>Select your photo:</label></td>
<td><input name="image" type="file" /></td>
</tr>
<tr>
<td><input type="submit" value="submit" /></td>
</tr>
</table>
</form>
</fieldset>
</body>
</html>

//...............................................................................................................................................
//Action.php

<html>
<body>
<?php
 $sname=$_POST['name'];
 $phone=$_POST['phone'];
 $email=$_POST['email'];
 $address=$_POST['address'];
 $contry=$_POST['con'];
 extract($_FILES['image']);
 /*print_r($_FILES);*/
 if($error==0)
 {
   if(($type="image/jpeg")||$type="image/pjpeg")
   {
    if(($size)/1024<=1000)
    {
     $path="upload";
     $filename=rand(1,1000)."_".$name;
     $act_path=$path."/".$filename;
     copy($tmp_name,$act_path);
     $f=1;
    }
    else
    {
     $msz="its too large! i can't handle it.";
    }
   }
   else
   {
    $msz="Opps! your file is not valid";
   }
 }
else
{
$msz="Error in the file!!";
}
if($f==1)
{
?>
<div style="width:550px;margin:0 auto;
padding:10px;background-color:#69F;
height:130px;box-shadow:#000 0 0 10px;">
<div style="float:right;border:1px solid #ccc;
padding:1px 2px;width:130px;
box-shadow:#aaa 0 0 10px;">
<?php
echo "<img src=\"$act_path\" height=100/>";
?>
</div>
<div style="float:left;padding-right:5px;">
<table style="text-align:left;color:#ffffff;
font-weight:bold;text-shadow:1px 1px #aaa;">
<tr>
<td>Name:</td>
<td style="text-align:left;color:yellow;">
<?php echo $sname; ?></td>
</tr>
<tr>
<td>Phone No:</td>
<td style="text-align:left;color:yellow;">
<?php echo $phone; ?></td>
</tr>
<tr>
<td>Email Id:</td>
<td style="text-align:left;color:yellow;">
<?php echo $email; ?></td>
</tr>
<tr>
<td>Address:</td>
<td style="text-align:left;color:yellow;">
<?php echo $address; ?></td>
</tr>
<tr>
<td>Country:</td>
<td style="text-align:left;color:yellow;">
<?php echo $contry; ?></td>
</tr>
</table>
</div>
</div>
<?php
}
else
{
header("location:image_form.php?data=$msz");
}
?>
</body>

</html>

download image or file from mysql database in php

// Download image or file from mysql database in php(down1).....



<html>
<head>
<title>Download File From MySQL Database</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<?php
//database connection
$con = mysql_connect('localhost', 'root', '') or die(mysql_error());
//select database
$db = mysql_select_db('bnr1', $con);
$query = "SELECT id, name FROM upload";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))
{
?>
<a href="download.php?id=<?php echo urlencode($id);?>"
><?php echo urlencode($name);?></a> <br>
<?php
}
}
mysql_close();
?>
</body>
</html>
<?php
if(isset($_GET['id']))
{
// if id is set then get the file with the id from database
$con = mysql_connect('localhost', 'root', '') or die(mysql_error());
$db = mysql_select_db('bnr1', $con);
$id    = $_GET['id'];
$query = "SELECT name, type, size, content " .
         "FROM upload WHERE id = '$id'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
ob_clean();
flush();
echo $content;
mysql_close();
exit;
}
?>

upload file or image into database in php mysql

//Upload file or image into database in php(up1)
//create table as follows..........

<html>
<head></head>
<body>
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1"
cellspacing="1" class="box">
<tr>
<td>please select a file</td></tr>
<tr>
<td>
<input type="hidden" name="MAX_FILE_SIZE"
value="16000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload"
type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['upload'])&&$_FILES['userfile']['size']>0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fileType=(get_magic_quotes_gpc()==0 ? mysql_real_escape_string(
$_FILES['userfile']['type']) : mysql_real_escape_string(
stripslashes ($_FILES['userfile'])));
$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}
$con = mysql_connect('localhost', 'root', '') or die(mysql_error());
$db = mysql_select_db('bnr1', $con);
if($db){
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
mysql_close();
echo "<br>File $fileName uploaded<br>";
}else { echo "file upload failed"; }
}
?>
end

Java Script validations in php using events


//Java Script validations in php using events

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<script type="text/javascript">
function user()
{
var name=document.form1.name.value;
var namexp=/^[a-zA-Z ]*$/;

if(name=="")
{
document.getElementById("d1").innerHTML="Please Enter Name";
document.form1.name.focus();
return false;
}
else if(!name.match(namexp))
{
document.getElementById("d1").innerHTML="Only letters";
return false;
}

else if(name.length<5)
{document.getElementById("d1").innerHTML="Minimum 5";
document.form1.name.focus();
return false;
}
else
document.getElementById("d1").innerHTML="";
return true;
}


function user1()
{
var mobile=document.form1.mobile.value;
var phexp=/^[0-9]+$/;
if(mobile=="")
{
document.getElementById("d2").innerHTML="Please Enter mobile Number";
document.form1.mobile.focus();
return false;
}
else if(!mobile.match(phexp))
{
document.getElementById("d2").innerHTML="Only Numbers";
return false;
}

else if(mobile.length!=10)
{
document.getElementById("d2").innerHTML="Invalid:Only 10 numbers";
return false;
}
else
document.getElementById("d2").innerHTML="";
return true;
}

function user2()
{
var email=document.form1.email.value;
var atpos=email.indexOf("@");
var dotpos=email.lastIndexOf(".");
if(email=="")
{
document.getElementById("d3").innerHTML="Please Enter email id!";
return false;
}
else if(atpos<1 || dotpos<atpos+2|| dotpos+2>=email.length)
{
document.getElementById("d3").innerHTML="Invalid Email Id";
return false;
}
else
{
document.getElementById("d3").innerHTML="";
return false;
}
}

function user3()
{
if((document.form1.gender[0].checked==false) && (document.form1.gender[1].checked==false))

{
document.getElementById("d4").innerHTML="Please Select Gender !";
return false;
}
else
{
document.getElementById("d4").innerHTML="";
return false;
}}

function user4()
{
var name=document.form1.name.value;
var mobile=document.form1.mobile.value;
var email=document.form1.email.value;
if(name=="")
{
document.getElementById("d1").innerHTML="Please Enter Name";
document.form1.name.focus();
return false;
}
if(mobile==""){
document.getElementById("d2").innerHTML="Please Enter mobile no";
document.form1.mobile.focus();
return false;
}
if(email=="")
{
document.getElementById("d3").innerHTML="Please Enter Email Id";
document.form1.email.focus();
return false;
}
if((document.form1.gender[0].checked==false) && (document.form1.gender[1].checked==false))
{
document.getElementById("d4").innerHTML="Please Select Gender";
document.form1.gender[0].focus();
return false;
}
}
</script>
<form id="form1" name="form1" method="post" action="onblur.php" >
  <table width="1000" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>&nbsp;</td>
      <td>Name</td>
      <td><input type="text" name="name" id="name" onblur="return user()" onkeyup="return user();" autocomplete="off" /></td>
      <td><div id="d1" style="color:#F00"></div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>Mobile</td>
      <td><input type="text" name="mobile" id="mobile" onblur="return user1()" onkeyup="return user1()" /></td>
      <td><div id="d2" style="color:#F00"></div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>Email</td>
      <td><input type="text" name="email" id="email" onblur="return user2()" onkeyup="return user2()" /></td>
      <td><div id="d3" style="color:#F00"></div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>Gender</td>
      <td>
        <label>
          <input type="radio" name="gender" value="male"  onblur="return user3()" onmouseup="return user3()"/>
          Male</label>
       
        <label>
          <input type="radio" name="gender" value="female" onmouseup="return user3()" />
          Female</label>
        <br />
      </td>
      <td><div id="d4" style="color:#F00"></div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><input type="submit" name="submit" id="submit" value="Submit" onclick="return user4()" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>

Friday 23 August 2013

Javascript validations in php using functions

//JavaScript Validations in php using onblur, onkeyup functions


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<script type="text/javascript">
function user()
{
var name=document.form1.name.value;
var namexp=/^[a-zA-Z ]*$/;

if(name=="")
{
document.getElementById("d1").innerHTML="Please Enter Name";
document.form1.name.focus();
return false;
}
else if(!name.match(namexp))
{
document.getElementById("d1").innerHTML="Only letters";
return false;
}

else if(name.length<5)
{document.getElementById("d1").innerHTML="Minimum 5";
document.form1.name.focus();
return false;
}
else
document.getElementById("d1").innerHTML="";

}


function user1()
{
var mobile=document.form1.mobile.value;
var phexp=/^[0-9]+$/;
if(mobile=="")
{
document.getElementById("d2").innerHTML="Please Enter mobile Number";
document.form1.mobile.focus();
return false;
}
else if(!mobile.match(phexp))
{
document.getElementById("d2").innerHTML="Only Numbers";
return false;
}

else if(mobile.length!=10)
{
document.getElementById("d2").innerHTML="Invalid:Only 10 numbers";
return false;
}

else
document.getElementById("d2").innerHTML="";

}
</script>
<form id="form1" name="form1" method="post" action="">
  <table width="1000" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="219">&nbsp;</td>
      <td width="70">&nbsp;</td>
      <td width="158">&nbsp;</td>
      <td width="470">&nbsp;</td>
      <td width="40">&nbsp;</td>
      <td width="43">&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>Name</td>
      <td><input type="text" name="name" id="name" onblur="return user()" onkeyup="return user();" autocomplete="off" /></td>
      <td><div id="d1" style="color:#F00"></div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>Mobile</td>
      <td><input type="text" name="mobile" id="mobile" onblur="return user1()" onkeyup="return user1()" /></td>
      <td><div id="d2" style="color:#F00"></div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>

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>