Friday, 14 February 2014

Mail Function

index.php




$mymail='vintechnosys@gmail.com';
sendmailtoclient($email,$mymail);
sendmailtoadmin($mymail,$email,$name,$subject,$message);


_________________________________________________________________________



function.php


<?php

function sendmailtoclient($toclient,$fromadmin)
{
$client=$toclient;
$subject="WELCOME TO VIN Technosys";
$message="Your enquiry has been received by us...We will contact you shortly<br>THANK YOU.";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <'.$fromadmin.'>' . "\r\n";
mail($client,$subject,$message,$headers);
echo"MESSAGE SENT";
}
function sendmailtoadmin($toadmin,$fromclient,$nam,$sub,$msg)
{

$toadmin=$toadmin;
$subject=$sub;
$message="ONE USER (".$nam.") with mailid(".$fromclient.") has enquired you as (".$msg.")";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <'.$fromclient.'>' . "\r\n";
mail($toadmin,$subject,$message,$headers);

}

?>

Tuesday, 11 February 2014

Form Validation


<!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
include("connect.php");
function test_input($data)
{
$data=trim($data);
$data=stripslashes($data);
$data=htmlspecialchars($data);
return $data;
}

$nameErr=$emailErr=$phoneErr="";
$myname=$myemail=$myphone="";

if($_SERVER['REQUEST_METHOD']=='POST')
{
$flag=1;
if(empty($_POST['name']))
{

$nameErr="* Name is required";
}
else
{
$myname=test_input($_POST['name']);
if(!preg_match("/^[a-zA-Z]*$/",$myname))
{
$flag=0;
$nameErr="* Only letters and white space";
}

}


if(empty($_POST['email']))
{

$emailErr="* email is required";
}
else
{
$myemail=test_input($_POST['email']);
if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$myemail))
{
$flag=0;
$emailErr="* Invalid email id";
}
}


if(empty($_POST['phone']))
{

$phoneErr="* Phone is required";
}
else
{
$myphone=test_input($_POST['phone']);
}
if(($flag==1)&& ($myname!="")&& ($myemail!="")&& ($myphone!=""))
{
$query=mysql_query("INSERT INTO myself VALUES ('','$myname','$myemail','$myphone')");
}


}

?>
<form method="post">
Name:<input name="name" type="text" /><?php echo $nameErr;?><br />
Email:<input name="email" type="text" /><?php echo $emailErr;?><br />
Phone:<input type="text" name="phone" /><?php echo $phoneErr;?><br />
<input type="submit" value="check" name="sub" />

</form>

</body>
</html>

Image Update


<!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=$_GET['edit_id'];
include("connection/connect.php");
$sql=mysql_query("SELECT * FROM img_up WHERE up_id=$id");
$fetch=mysql_fetch_array($sql);
$name=$fetch['up_name'];
$oldimg=$fetch['up_image'];
echo $oldimg;
?>
<form method="post" enctype="multipart/form-data">
Name:<input type="text" name="name" value="<?php echo $name ;?>" />
Image:<input type="file" name="photo" />
<input type="submit" value="update" name="sub" />
</form>
<?php
include("connection/connect.php");
if(isset($_POST['sub']))
{
$q_name=$_POST['name'];
$q_image=$_FILES['photo'];
if(!empty($q_image['name']))
{
$folder='images/';
unlink($folder.$oldimg);
/*-------Check point for photo--------------*/
if($q_image['type']="images/jpeg"||$q_image['type']="images/jpg"||$q_image['type']="images/png"&&($q_image['size']<1000000))
{
/*create folder for image upload*/



/*Checking whether image name already availiable in the folder*/
if(file_exists($folder.$q_image['name']))
{
$ran_num=rand(0000,9999);
$now_name=$ran_num.$q_image['name'];
}
else
{
$now_name=$q_image['name'];
}
/*Moving the image to the created folder with the unique name*/
move_uploaded_file($q_image['tmp_name'],$folder.$now_name);
}

$upquery=mysql_query("UPDATE img_up SET up_name='$q_name',up_image='$now_name' WHERE up_id=$id");
}
else
{
echo "pls select image";
$upnquery=mysql_query("UPDATE img_up SET up_name='$q_name' WHERE up_id=$id");
}
}
?>
</body>
</html>

Image Upload


<!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--------------------------->


<form method="post" enctype="multipart/form-data">
Name <input type="text" name="name" /><br />
Image <input type="file" name="photo" /><br />
<input type="submit" name="sub"  value="upload"/><br />
</form>
<!------------Getting values fron form------>
<?php
            include("connection/connect.php");
            if(isset($_POST['sub']))
            {
$q_name=$_POST['name'];
$q_image=$_FILES['photo'];
/*-------Check point for photo--------------*/
if($q_image['type']="images/jpeg"||$q_image['type']="images/jpg"||$q_image['type']="images/png"&&($q_image['size']<1000000))
{
/*create folder for image upload*/
$folder='images/';
/*Checking whether image name already availiable in the folder*/
if(file_exists($folder.$q_image['name']))
{
$ran_num=rand(0000,9999);
$now_name=$ran_num.$q_image['name'];
}
else
{
$now_name=$q_image['name'];
}
/*Moving the image to the created folder with the unique name*/
move_uploaded_file($q_image['tmp_name'],$folder.$now_name);
}
$upquery=mysql_query("INSERT INTO img_up VALUES ('','$q_name','$now_name')");

}


?>
<form method="post">
id:<input type="text" name="myimg" /><br />
<input type="submit"  name="showit"/>
</form>
<?php
include("connection/connect.php");
if(isset($_POST['showit']))
{
$myid=$_POST['myimg'];
$fetch=mysql_query("SELECT * FROM img_up WHERE up_id='$myid'");
$fetchimage=mysql_fetch_array($fetch);

?>
<img src="images/<?php echo $fetchimage['up_image']; ?>" width="132" height="99">
<?php
}
?>
   
    <a href="list_images.php">list</a>
 



</body>
</html>