Gadgets

Friday, 8 August 2014

Simple PHP Project for beginners



Simple PHP Project:
In this article I explained a simple PHP Project, in this project I done registration, login, update profile, delete profile, and logout operations.
I posted code here clearly and I drawn a flow chart for clear understanding.

Project flowchart: 



Database file:

Name
Varchar(20)
uid(primary key)
Varchar(30)
password
Varchar(20)
gender
Text(8)
dob
Date(15)
ph_number
Int(12)
security_q
Text(30)
security_a
Varchar(30)


Database connection PHP file:
<?php
$con=  mysql_connect("localhost","user","12345");
/*mysql_connect(servername,username,password);*/
if(!$con){
    die ("could not connect".  mysql_connect());
}
$db=  mysql_select_db(&apos;narendar&apos;);
if(!$db){
    die("Database is unavailable".mysql_error());
}
?>
Registration HTML file:
In this registration form I added client side validation and I taken 9 fields (name, email id, password, reenter password, gender, phone number, security question, and security answer).
<form action="register.php" method="post">
        <table>
            <tr><td>Name :</td><td><input type="text" name="na" required/></td></tr>
            <tr><td>Email id :</td><td><input type="email" name="email"pattern="*@*.+" required/></td></tr>
            <tr><td>Password :</td><td><input type="password" name="psw"pattern="[A-Za-z0-9!@#$%^&*()_]{8,30}"onchange="this.setCustomValidity(this.validity.patternMismatch ? &apos;Password contain at least 8 charecters&apos;:&apos;&apos;);if(this.checkValidity())form.cpsw.pattern=this.value"required/></td></tr>
            <tr><td>Reenter Password :</td><td><input type="password" name="cpsw"onchange="this.setCustomValidity(this.validity.patternMismatch ? &apos;Please enter same password as above&apos;:&apos;&apos;);"required/></td></tr>
            <tr><td>Gender :</td><td><input type="radio" name="gender" value="male" required/>Male
                                     <input type="radio" name="gender" value="female" required/>Female</td></tr>
            <tr><td>Birth Date :</td><td><input type="date" name="date"required/></td></tr>
            <tr><td>Phone Number :</td><td><input type="tel" name="phno"pattern="[0-9]{10}"required /></td></tr>
         
            <tr><td>Security Question :</td><td>
                    <select name="sq"required>
                        <option value="">Select question</option>
                        <option value="who is your best friend">Who is your best friend</option>
                        <option value="what is your favorite color">What is your favorite color</option>
                        <option value="what you like most in this world">What you like most in this world</option>
                    </select>
                </td></tr>
            <tr><td>Security Answer :</td><td><input type="text" name="sa"required/></td></tr>
            <tr><td></td><td><input type="checkbox" name="tc" value="ON"required />Accepted Terms and Conditions</td></tr>
             <tr><td></td><td><input type="submit" value="Signup" name="Signup" /></td></tr>
        </table>
        </form>
Registration PHP file:
<?php
include("database_connection.php");
session_start();
$r="insert into user (name,uid,password,gender,dob,ph_number,security_q,security_a)values(&apos;$_POST[na]&apos;,&apos;$_POST[email]&apos;,
&apos;$_POST[psw]&apos;,&apos;$_POST[gender]&apos;,&apos;$_POST[date]&apos;,&apos;$_POST[phno]&apos;,&apos;$_POST[sq]&apos;,&apos;$_POST[sa]&apos;)";
if(!mysql_query($r,$con))
{
die(&apos;error:&apos;.mysql_error());
}
else{
echo "successfully registred";
header("location:login.php");
}
?>
If registration is successful it will for login page
Login HTML file:
<form action="login_ser.php" method="post">
            <table>
                <tr><td>Email id :</td><td><input type="email" name="email"pattern="*@*.+" required/></td></tr>
                <tr><td>Password :</td><td><input type="password" name="psw"pattern="[A-Za-z0-9!@#$%^&*()_]{8,30}"required/></td></tr>
                <tr><td></td><td><input type="submit" value="Singin" name="Signin" /></td></tr>
            </table>
        </form>
Login PHP file:
<?php
        // put your code here
        include "database_connection.php";
        session_start();
        $email=$_POST["email"];
        $psw=$_POST["psw"];
        $r=mysql_query("select * from user where uid="$email" and password="$psw"");     
         
           while($row = mysql_fetch_array($r)){
               $dbuid=$row["uid"];
               $dbpsw=$row["password"];
               $user_name=$row["name"];
               if($dbuid==$email&&$dbpsw==$psw){
                   session_register("dbuid");
               $_SESSION["login_user"]=$dbuid;
               header("location:home.php");
               }        
           else{
               echo "incorrect user id and password";
               header("location:login.php");
           }         
           }  
        ?>
In this login PHP file create the session and get that session id into Session PHP file. in this session php file check that login user is available or not, and  get values of login user from the database.
Session PHP file:
<?php
        // put your code here
        session_start();
               $se_uid=$_SESSION["login_user"];
               include "database_connection.php";
             $sql= mysql_query("select * from user where uid="$se_uid"");
              $row = mysql_fetch_array($sql);
            $login_name=$row["name"];
            $l_uid=$row["uid"];
            $l_dob=$row["dob"];
            $l_phno=$row["ph_number"];
        ?>
If login is successful it will go for Home page
Welcome Home PHP:
<?php
        // put your code here
        include "session.php";
        ?>
        <h3>Welcome <?echo $login_name;?></h3>
        <nav>
            <a href="home.php">Home</a>&nbsp;|&nbsp;
            <a href="update.php">Update Profile</a>&nbsp;|&nbsp;
            <a href="delete.php">Delete Account</a>&nbsp;|&nbsp;
           <a href="logout.php">Logout </a>
        </nav>
Update HTML file:
<?php
        // put your code here
        include "session.php";
        ?>
         <form action="update_ser.php"method="post">
        <table>
            <tr><td>Email id :</td><td><?echo $l_uid;?></td></tr>
                        <tr><td>Name :</td><td><input type="text" name="na" value="<?echo $login_name;?>"required/></td></tr>          
            <tr><td>Birth Date :</td><td><input type="date" name="date"value="<?echo $l_dob;?>"required/></td></tr>
            <tr><td>Phone Number :</td><td><input type="tel" name="phno"pattern="[0-9]{10}"value="<?echo $l_phno;?>"required /></td></tr>
  <tr><td></td><td><input type="submit" value="Update" name="Update" /></td></tr>
        </table>
        </form>
Update PHP file:
<?php
        // put your code here      
        include "session.php";
        $u_name=$_POST["na"];
        $u_phno=$_POST["phno"];
        $u_date=$_POST["date"];
        $sql="update user set name="$u_name",dob="$u_date",ph_number="$u_phno"where uid="$l_uid"";
          if(!mysql_query($sql)){
            die("error".mysql_error());
        }
        else{
            header("location:home.php");
        }     
        ?>
Delete PHP file:
<?php
        // put your code here
        include "session.php";
        $sql= mysql_query("delete from user where uid="$se_uid"");
        echo "your account deleted";
        ?>
        <a href="index.php">Click here to register again</a>

Logout PHP file:
<?php
session_start();
if(session_destroy())
{
header("Location: login.php");
}

?>

Screen shorts: 

Wednesday, 23 July 2014

CSS3 Shapes chat bubble

Circle symbol:
#circle{
                width: 200px;
                height: 200px;
                border-radius:50%;
                background:linear-gradient(top, #054d52 0%, #057178 100%);
               background:-webkit-linear-gradient(top, #054d52 0%,#057178 100%);
                       background: -moz-linear-gradient(top, #054d52 0%, #057178 100%);
                background: -ms-linear-gradient(top, #054d52 0%, #057178 100%);
                 background: -o-linear-gradient(top, #054d52 0%, #057178 100%);
       
            }
 
<div id="circle">
        </div>
 
 
Chat bubble symbol:
#chat-symbol{
                width: 100px;
                height: 80px;
                background:  #054d52;
                position: relative;
                border-radius:8px;
            }
            #chat-symbol:before{               
                content: "";
                position: absolute;
                left:  100%;
                top: 26px;
                border-top: 13px solid transparent;
                border-left:  26px solid #054d52;
                border-bottom: 13px solid transparent;
            }
 
<div id="chat-symbol">           
        </div>
JSP Page

CSS3 Search Shape



CSS Shapes:

Search Symbol: 

 /*Circle syles*/
#search  {                              
                                 border: 5px solid #56276a; /*circle border and color*/
                                 border-radius:50%; /*circle border radius*/
                                 width: 50px; /*circle width*/
                                 height: 50px;  /*circle height*/
                                 position: relative; /*circle position*/
                             }

/*circle handle styles*/

                             #search:before{
                                 content: "";
                                 width: 5px;
                                 height: 40px;
                                 background:#56276a;
                                 position: absolute;
                                 right: -7px;  /* line right */
                                 bottom: -30px; /* line bottom */
                                transform: rotate(145deg);  /* line rotation */
                                 -webkit-transform: rotate(145deg);
                                 -moz-transform: rotate(145deg);
                                 -ms-transform: rotate(145deg);
                                 -o-transform: rotate(145deg);
                             }

<div id="search">            
         </div>

Saturday, 19 July 2014

"Before" and "After" Selectors in CSS3



"Before" and "After" Selectors in CSS3
 <style>
p::before
{
content:"I am Narendar:-";
background-color:#FFFF66;
color:red;
font-weight:bold;
}
</style>
<p>this is before selector</p>

<style>
p::after
{
content:"I am Narendar:-";
background-color:#FFFF66;
color:red;
font-weight:bold;
}
</style>

<p>this is after selector</p>


this is before selector

this is after selector