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>