Saturday 28 February 2015

PHP script for email verification or confirmation in php?

(1) first create table user:

create table user
(id int primary key auto_increment,

name varchar(200),
email varchar(200),
phone varchar(200),
password varchar(200),
com_code varchar(200));


(2)write code for connect.php file:

<?php

$con=mysql_connect("localhost","root","");
mysql_select_db("itexamtime",$con) or die(mysql_error());

?>

(3)write code for registerform.php file:
<?php


echo '<form action="insert1.php"   method="post">
      Name<input type=text name="name">
 Email<input type=email name="email">
 phone  <input type=text    name="phone">
 password<input type=password name="password">
 <input  type=submit  name=submit value=submit>';

 
?>

(4)write code for insert1.php file:



<?php
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$password=$_POST['password'];
$com_code=md5(uniqid(rand()));
include_once("connect.php");

$sql="insert into user(name,email,phone,password,com_code)values('$name','$email','$phone','$password','$com_code')";

$result=mysql_query($sql) or die(mysql_error());

if($result)
  {
   $to = $email;
   $subject = "Confirmation from TutsforWeb to $username";
   $header = "ItexamTime: Confirmation LInk";
 
   $message .= "http://funmoviemasti.com/confirm.php?passkey=$com_code";

   $sentmail = mail($to,$subject,$message,$header);

   if($sentmail)
            {
   echo "Your Confirmation link Has Been Sent To Your Email Address.";
   }
   else
         {
    echo "Cannot send Confirmation link to your e-mail address";
   }

}

?>

(5)write code for confirm.php file:

<?php

include_once("connect.php");

$passkey = $_GET['passkey'];

 $sql="update user set com_code='1'  where com_code='$passkey'";

$result=mysql_query($sql) or die(mysql_error());

if($result)

{


echo "your account is active ";




}



?>







Friday 27 February 2015

PHP Script for Dynamic Drop down List

(1)create table   account:


create table account
(
id  int(5) primary key auto_increment,
name  varchar(20),
contact  varchar(20),
address  varchar(200),
emailid  varchar(20),
account   varchar(20),
password   varchar(20),
image      varchar(200),
idproof     varchar(200),
addressproof varchar(200));

(2)insert some values  into table
(3) then use following code :


<html>
<head>
<title>
Deposit money
</title>
</head>

<body>
<form   >
<select name=account>
<?php

include("connect.php");

$sql="select * from account";

$result=mysql_query($sql);

while($row=mysql_fetch_array($result))
{

echo '<option value="'.$row['id'].'">';

echo $row['id'];

echo '</option>';

}

?>
</select>
<form>
</body>
</html>

Undefined Index problem in PHP


this problem comes when you do not declare  name
so overcome this use following code:


$mobile=isset($_POST['mobile']) ? $_POST['mobile'] : 'Null';

Thursday 26 February 2015

PHP script for file Upload

PHP script for file Upload

(1)step 1: write code for  "slider.html"

<form action="sliderupload.php"   method="post"  enctype="multipart/form-data">
UPload<input type="file"  name="image">
 <input type="submit"  name="submit"  value="Upload">


</form>

(2)step 2: write code for  "sliderupload.html"


<?php

$image=$_FILES['image']['name'];

include("connect.php");

$sql="insert into slider(image)values('$image')";

mysql_query($sql) or die(mysql_errror());

move_uploaded_file($_FILES['image']['tmp_name'],"slider/".$_FILES['image']['name']) or die(mysql_error());

?>

(3)write code for class.php file :

<?php


class db

{

var $host="servername";

var  $username="username";

var  $password="password";

function connect()
{

$connect=mysql_connect($this->host,$this->username,$this->password);

mysql_select_db("a1390987_om",$connect) or die(mysql_error());

if(!$connect)
{

echo "connection error ";
}





}

function display($table)
{


$sql="select * from $table ";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);




return $row;

}


}

$obj=new db();
$obj->connect();



?>


(4)use img tag to display image & write following code for displayslider.php:

<?php

include("class.php");

$table="slider";

$slider=$obj->display($table);

$image=$slider['image'];

echo $image;



echo "<img  src='slider/".$image."'   height=200 width=200   border=10 >";





?>

PHP Script for Admin login with session management & Logout

(1)first  write following code for Login form   "loginform.html"  file

<form action="login.php"  method="post">
<table border=0>
<tr><td>User name:</td>
<td>
                                         <input name="username" type="TEXT"></td> </tr>
                                  <tr><td>Password</td><td>
                                         <input name="Password" type="PASSWORD"></td>
                                         </tr>
                                       
                                   

                                    <tr>
                                        <td></td><td><input value="submit" name="SubmitUser" type="submit"></td>
</form>
                                    </tr>
                                </table>


(2) Then write code for  "login.php" file

<?php



$username=$_POST['username'];
$password=$_POST['password'];
$con=mysql_connect("hostname","username","password") or die(mysql_error());

mysql_select_db("databasename",$con);

$sql="select username,password  from login where username='$username'  AND password='$password'";

$result=mysql_query($sql) or die(mysql_error());

$num=mysql_num_rows($result) or die(mysql_error());


if($num>0)
{

 session_start();

 $_SESSION['username']=$username;

header("Location:dashboard.php");

}

else if($num==0)
{
header("Location:error.php");
}



?>


(3)Session management code:



<?php

session_start();
if(!isset($_SESSION['username']))
{

header("Location:index.php");

}


?>
NOte:
write this code on every your page starting or simply save it as

session.php  & on every page use it as

<?php  include("session.php");   ?>


(4)Logout code : save file name as "logout.php"

see below code:

<?php

session_start();

session_destroy();

header("Location:loginform.html");

?>


Tuesday 24 February 2015

how to use ckeditor in php ?
(1)download   (ckeditor_3.6.6)
(2)user following code to link:
<?php
    include("ckeditor/ckeditor.php");
    $CKeditor = new CKeditor();
    $CKeditor->BasePath = 'ckeditor/';
    $CKeditor->editor('editor1');
?>


& use can also use another following code :



<?php require("ckeditor/ckeditor.php"); ?>

 <script type="text/javascript" src="ckeditor/ckeditor.js"></script>
 <script type="text/javascript" src="somedirectory/ckeditor/ckeditor.js"></script>






<textarea class="ckeditor" name="editor1">Write any thing</textarea>

Wednesday 18 February 2015

Login page code in PHP


 (1)first create file index.html


<form action="login.php"  method="post">
                     <span class="loginText">User name:</span><br>
                                         <input name="username" type="TEXT"><br>
                                         <span class="loginText">Password:</span><br>
                                         <input name="Password" type="PASSWORD">
                                         <br>
                                         <span class="loginText">login as user: <i>demo</i><br>with password: <i>anahaw</i></span>
                                        </td>
                                    </tr>

                                    <tr>
                                        <td align="right"><input value="submit" name="SubmitUser" type="submit"></td>
                                        </form>

(2)create login.php file

<?php

$username=$_POST['username'];
$password=$_POST['Password'];
$con=mysql_connect("localhost","root","") or die(mysql_error());

mysql_select_db("payroll",$con);

$sql="select username,password  from login where username='$username'  AND password='$password'";

$result=mysql_query($sql) or die(mysql_error());

$num=mysql_num_rows($result) or die(mysql_error());


if($num>0)
{
 session_start();
 $_SESSION['username']=$username;
header("Location:welcome.php");

}

else
{
echo "invalid login";
}

?>



Pagination in PHP



<?php

    mysql_connect("localhost","root","")or die("Problems...");
    mysql_select_db("payroll");

    $per_page = 2;
    $pages_query = mysql_query("SELECT COUNT('id') FROM  employee");
    echo $pages_query."<br>";
    $pages = ceil(mysql_result($pages_query, 0) / $per_page);
    echo $pages;
  
    $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
    $start = ($page - 1) * $per_page;
  
    $query = mysql_query("SELECT *  FROM employee LIMIT $start, $per_page");
  
    while($row = mysql_fetch_assoc($query))
  
  
    {
  
  

echo '<form action=update.php  method=post      enctype="multipart/form-data">
<table border=1  cellspacing=3 cellpadding=2 bgcolor=orange  bordercolor=black>
<tr><td>DATE OF SIGN UP</td><td><INPUT TYPE=TEXT NAME="name"  value="'.$row['name'].'"></td></tr>
<tr><td>NAME</TD><td><INPUT TYPE=TEXT NAME="phone"      value="'.$row['phone'].'"></td></tr>
<tr><td>ADDRESS</TD><TD><input type=text name="salary"        value="'.$row['salary'].'"></td></tr>

<tr><td> </td><td>
<input type=hidden name=hidden  value="'.$row['emp_id'].'">
<input type=submit name=update value=update></td></tr>


</TABLE>


</FORM>';


  
  
  
    }
  
    $prev = $page - 1;
    $next = $page + 1;
  
    if(!($page<=1)){
        echo "<a href='pagination1.php?page=$prev'>Prev</a> ";
    }

    if($pages>=1 && $page<=$pages){
  
        for($x=1;$x<=$pages;$x++){
            echo ($x == $page) ? '<strong><a href="?page='.$x.'">'.$x.'</a></strong> ' : '<a href="?page='.$x.'">'.$x.'</a> ';
      
        }
  
    }
  
    if(!($page>=$pages)){
        echo "<a href='pagination1.php?page=$next'>Next</a>";
    }
  
  
?>

Ajax with PHP & Mysql database

(1) create file  index.html



 <html>
<head>
<script>
function showUser() {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else {
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","getuser.php?",true);
        xmlhttp.send();
    }
}
</script>
</head>
<body>

<form name="users"  onclick="showUser()">

<input type=submit value=submit   >

</form>
<form>
<select name="users" onchange="showUser()">
  <option value="">Select a person:</option>
  <option value="1">Peter Griffin</option>
  <option value="2">Lois Griffin</option>
  <option value="3">Joseph Swanson</option>
  <option value="4">Glenn Quagmire</option>
  </select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here...</b></div>

</body>
</html>

(2) then create file

getuser.php






<!DOCTYPE html>
<html>
<head>
<style>
table {
    width: 100%;
    border-collapse: collapse;
}

table, td, th {
    border: 1px solid black;
    padding: 5px;
}

th {text-align: left;}
</style>
</head>
<body>

<?php
//$q = intval($_GET['q']);

$con = mysqli_connect('localhost','root','','my_db');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"ajax_demo");
//$sql="SELECT * FROM user WHERE id = '".$q."'";

$sql="SELECT * FROM user";

$result = mysqli_query($con,$sql);

echo "<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['FirstName'] . "</td>";
    echo "<td>" . $row['LastName'] . "</td>";
    echo "<td>" . $row['Age'] . "</td>";
    echo "<td>" . $row['Hometown'] . "</td>";
    echo "<td>" . $row['Job'] . "</td>";
    echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html>