Friday, April 10, 2015

how to code for captcha in php

Hallo friends ...i am going to tell you how to write a code for captcha in php..

Thursday, March 26, 2015

Form validation through PHP in-build function

Hallo Guys
Now i am showing you how to
validate variables in PHP.
ins this post we also discuss PHP INBUILD FUNCTION for email and phone no. validation.


# Get values from user & print in front
<?php
$name = ' ';    //by default we declare variables none
$age = ' ';    //by default we declare variables none
$password = '';    //by default we declare variables none
$mail = ' ';    //by default we declare variables none
$phone= ' ';    //by default we declare variables none
$doj =  ' ';    //by default we declare variables none
$pass= ' ';    //by default we declare variables none
$error = ' ';    //by default we declare variables none
// check if user press the submit button then follow
if(isset($_POST['submit']))
{
$name=$_POST['uname'];
$age=$_POST['age'];
$password=$_POST['password'];
$pass=strlen($password);
$mail=$_POST['mail'];
$phone=$_POST['phone'];
$doj=$_POST['doj'];
// check field value is empty or not
// if empty then store error in error variabl
if(empty($name))
{
$error="please enter the user name";
}
else if(empty($age))
{
$error="please enter the age";
}
else if(empty($password))
{
$error="please enter the password";
}
else if($pass<=6)
{
$error="password must be more then 6 character";
}
else if(empty($mail))
{
$error="please enter the mail";
}
else if(!filter_var($mail, FILTER_VALIDATE_EMAIL)) // check email validation by php inbuild function
{
$error="enter a valid email";
}
else if(empty($phone))
{
$error="please enter the phone no.";
}
else if(empty($doj))
{
$error="please enter the date of Joining.";
}

}
?>
<table width="30%" align="center" border="1px">
<tr bgcolor="#990000">
    <th style="color:#FFFFFF">Field</th><th style="color:#FFFFFF">Input Values</th>
</tr>
<tr>
<td>Name : </td><td><?php echo $name; ?></td>
</tr>
<tr>
<td>Age : </td><td><?php echo $age; ?></td>
</tr>
<tr>
<td>Password : </td><td><?php echo $password; ?></td>
</tr>
<tr>
<td>Mail : </td><td><?php echo $mail; ?></td>
</tr>
<tr>
<td>Phone : </td><td><?php echo $phone; ?></td>
</tr>
<tr>
<td>Date of Joining : </td><td><?php echo $doj; ?></td>
</tr>
</table>
<br />
<!-- Display error message if found -->
<p style="color:red;">
<?php
if(isset($error))
{
 echo $error;
}?>
</p>

<!-- we empty form action because we display values same page --->

<form action="" method="post">
<table align="center" width="45%" border="1px">
    <tr bgcolor="#990000">
        <th style="color:#FFFFFF">Field</th><th style="color:#FFFFFF">Input Values</th>
    </tr>
<tr>
    <td>User Name</td>
    <td><input type="text" name="uname" value="Name" /></td>
 </tr>
 <tr>
        <td>Age</td>
        <td><input type="text" name="age" value="Age" /></td>
 </tr>
    <tr>
        <td>Password</td>
        <td><input type="text" name="password" value="Password" /></td>
    </tr>
    <tr>
        <td>Mail</td>
        <td><input type="text" name="mail" value="Email" /></td>
    </tr>
    <tr>
        <td>Phone</td>
        <td><input type="text" name="phone" value="Phone" /></td>
    </tr>
    <tr>
        <td>Date of Joining</td>
        <td><input type="date" name="doj" value="Date of Joining" /></td>
    </tr>
    <tr>
        <td colspan="2" style="padding-left:150px;"><input type="submit" name="submit" value="Show" />&nbsp;&nbsp;&nbsp;<input type="reset" name="reset" value="Clear" /></td>
    </tr>
</table>
</form>

Get user values and Display without database

Here is simple php program to get values from user and display the values without database.



# Get values from user & print in front
<?php

$name = ' ';    //by default we declare variables none
$age = '';    //by default we declare variables none
$type = '';    //by default we declare variables none
$status = '';    //by default we declare variables none
$doj = '';    //by default we declare variables none

// check if user press the submit button then follow
if(isset($_POST['submit']))
{
$name=$_POST['uname'];  // store values in variables
$age=$_POST['age'];
$type=$_POST['type'];
$status=$_POST['status'];
$doj=$_POST['doj'];
}
?>
<table width="30%" align="center" border="1px">
<tr bgcolor="#990000">
    <th style="color:#FFFFFF">Field</th><th style="color:#FFFFFF">Input Values</th>
</tr>
<tr>
<td>Name : </td><td><?php echo $name; ?></td>
</tr>
<tr>
<td>Age : </td><td><?php echo $age; ?></td>
</tr>
<tr>
<td>Type : </td><td><?php echo $type; ?></td>
</tr>
<tr>
<td>Status : </td><td><?php echo $status; ?></td>
</tr>
<tr>
<td>Date of Joining : </td><td><?php echo $doj; ?></td>
</tr>
</table>
<br />
<!-- call same page through php_self function or we can also call page through file name -->
<form action="<?php echo $_SERVER['PHP_SELF'];  ?>" method="post">
<table align="center" width="35%" border="1px">
    <tr bgcolor="#990000">
        <th style="color:#FFFFFF">Field</th><th style="color:#FFFFFF">Input Values</th>
    </tr>
<tr>
    <td>User Name</td><td><input type="text" name="uname" value="Name" /></td>
    </tr>
    <tr>
        <td>Age</td><td><input type="text" name="age" value="Age" /></td>
    </tr>
    <tr>
        <td>Type</td><td><input type="text" name="type" value="Type" /></td>
    </tr>
    <tr>
        <td>Status</td><td><input type="text" name="status" value="Status" /></td>
    </tr>
    <tr>
        <td>Date of Joining</td><td><input type="date" name="doj" value="Date of Joining" /></td>
    </tr>
    <tr>
        <td colspan="2" style="padding-left:150px;"><input type="submit" name="submit" value="Show" />&nbsp;&nbsp;&nbsp;<input type="reset" name="reset" value="Clear" /></td>
    </tr>
</table>
</form>

Wednesday, March 25, 2015

Create a simple database connection in PHP

Here is the simple php mysql database connection.

i'll put more option later.


<?php
//$conn=mysqli_connect("host","username","password","database");
$conn=mysqli_connect("localhost","root","","2phpmysql");
if(!$conn)
{
die ('connection error').mysqli_error();
}

?>

we'll discuss more about above in next tutorials.