TUTORIALS

PHP TUTORIALS

I use for designing Dreamweaver 


You can use any other software like Joomla for designing


 I use WampServer to run the PHP file

Here some PHP programming and the Programming PHP files are given. You can copy the code or can download and then run it in your browser through WampServer. If you can't understand or get any trouble to understand then contact with me. To contact me Click Here.

Get data from a database table into a page

Here database name  “myname” and table name “user” and “user” fields name (`name,`pnone`,`email`).

form.php

<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<?php
//connection to DB
$link = mysql_connect("localhost", "root", "") or die ("problem is occored");
mysql_select_db("myname");
$query = ("SELECT * FROM `user`");
$result = mysql_query($query);
if($result)
                {
                                echo "<h4>Here are the results:</h4><br><br>";
                                echo "<table width=50% align=center border=0><tr>
                                <td align=center bgcolor=#00FFFF><b>Name</b></td>
                                <td align=center bgcolor=#00FFFF><b>Phone No</b></td>
                                <td align=center bgcolor=#00FFFF><b>Email id</b></td>
                               
                                </tr>";

                                while($r = mysql_fetch_array($result))
                                { // Begin while
                                                $a=$r["name"];
                                                $b=$r["pnone"];
                                                $c=$r["email"];
                                                echo "<tr>
                                                <td align=left bgcolor=#C0C0C0><b>$a</td>
                                                <td align=center bgcolor=#C0C0C0><b>$b</td>
                                                <td align=center bgcolor=#C0C0C0><b>$c</td>
                                               
                                                </tr>";
                                } // end while
                echo "</table>";
                }
else
                {
                echo "problems....";
                }
mysql_close($link);
?>
</body>
</html>



-------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------
Insert data into database table using PHP



Here database name  “samit2” and table name “table1” and “table1” fields name  (`name`,`addr`,`phone`,`email`)  and there will be a another field in “table1” is `id` which is auto incremented, It shows you as a code when your data will be inserted into database.


Insertdata.php

<form id="form1" name="form1" method="post" action="insert2.php">
  <table width="507" align="center">
    <tr>
      <td colspan="2"><div align="center" class="style1">Entry Form  </div></td>
    </tr>
    <tr>
      <td><div align="right"><span class="style2">Name:</span></div></td>
      <td><div align="left">
          <input name="nm" type="text" id="nm" />
          <span class="style3">*</span></div></td>
    </tr>
    <tr>
      <td><div align="right"><span class="style2">Address:</span> </div></td>
      <td><label>
          <div align="left"><span class="style3">
            <label>
            <textarea name="addr" id="addr"></textarea>
            </label>
            *</span></div>
        </label></td>
    </tr>
    <tr>
      <td><div align="right"><span class="style2">Email Id :  </span></div></td>
      <td><div align="left">
          <script type="text/javascript" src="file:///C|/Documents and Settings/SAMIT/Desktop/new/js/calendarDateInput.js"></script>
          <script>DateInput('birth_date1', true, 'YYYY-MM-DD')</script>
          <label>
          <input name="email" type="text" id="email" />
          </label>
      </div></td>
    </tr>

    <tr>
      <td><div align="right"><span class="style2">Phone Number:</span></div></td>
      <td><label>
          <div align="left">
            <label>
            <input name="ph" type="text" id="ph" />
            </label>
            <span class="style3">*</span></div>
        </label></td>
    </tr>
    <tr>
      <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2"><label>
          <div align="center">
            <input type="submit" name="Submit" value=" Save " />
            </label>
        </div></td>
    </tr>
  </table>
</form>
</body>
</html>

Insert.php

<?php

$link=mysql_connect("localhost","root","") or die ("Problem connecting to DataBase");
mysql_select_db("samit2");

$nm=trim($_POST['nm']);
$addr=trim($_POST['addr']);
$email=trim($_POST['email']);
$ph=trim ($_POST['ph']);


$query = "insert into `table1`
                                (`name`,`addr`,`phone`,`email`) 
                                values('$nm','$addr','$ph','$email')";
                                                   
$sql=mysql_query($query);
                                                                               
echo "Successfuly Inserted Data<br>";
$query1 = ("SELECT `id` FROM `table1` where `name`='$nm'");
$result = mysql_query($query1);
if($result)
{

while($r = mysql_fetch_array($result))
                                { // Begin while
                                                $a=$r["id"];
                                                echo"Here are your code:";
                                                echo "$a","<br/>";
                                } // end while
}
else
                {
                echo "problems....";
                }
               
mysql_close($link);
                                                                               
?>

<a href = "insertdata.php"> Back</a>

---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
Insert value to multiple table





Here database name  “email” and table name “user”, “recovery”,  “login” and “user” fields name (`name`, `phone`, `uid`, `paswrd`, `question`, `answer`) and “recovery” fields name (`question`, `answer`, `uid`, `paswrd`)  and “login” fields name (`uid`,`paswrd`)   

reg.php

<html>
<head>
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
                color: #990000;
                font-weight: bold;
}
.style2 {
                color: #660099;
                font-weight: bold;
}
.style3 {
                color: #000066;
                font-weight: bold;
}
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="reg1.php">
  <table width="649" border="0" align="center">
    <tr>
      <td>&nbsp;</td>
      <td><div align="center" class="style1"></div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><div align="center"><span class="style1">REGISTRATION FORM</span></div></td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <table width="200" border="0" align="center">
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <table width="409" border="0" align="center">
    <tr>
      <td width="152"><div align="right" class="style3">Name : </div></td>
      <td width="234"><label>
        <input name="name" type="text" id="name" />
      </label></td>
      <td width="9">&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right" class="style3">Phone No : </div></td>
      <td><input name="phone" type="text" id="phone" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right" class="style3">User Id : </div></td>
      <td><input name="uid" type="text" id="uid" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right" class="style3">Password : </div></td>
      <td><input name="paswrd" type="password" id="paswrd" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2"><div align="center" class="style2">If You Forgot Password </div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right" class="style3">Select a Question : </div></td>
      <td><label>
        <select name="question" id="question">
          <option>what is your nick name</option>
          <option>what is your mobile no</option>
          <option>your school name</option>
        </select>
      </label></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right" class="style3">Your Answer : </div></td>
      <td><input name="answer" type="text" id="answer" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right"></div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="  Creat  " /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label></label></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>
</body>
</html>

reg1.php

<?php
$link=mysql_connect("localhost","root","") or die ("Problem connecting to DataBase");
mysql_select_db("email");

$name=trim($_POST['name']);
$phone=trim($_POST['phone']);
$uid=trim($_POST['uid']);
$paswrd=trim ($_POST['paswrd']);
$question=trim($_POST['question']);
$answer=trim($_POST['answer']);

$query = "insert into `user`
                                (`name`,`phone`,`uid`,`paswrd`,`question`,`answer`) 
                                values('$name','$phone','$uid','$paswrd','$question','$answer')";
                               
$sql=mysql_query($query);
                               
$query1 = "insert into `recovery`
                                (`question`,`answer`,`uid`,`paswrd`) 
                                values('$question','$answer','$uid','$paswrd')";
                               
$sql1=mysql_query($query1);
                               
$query2 = "insert into `login`
                                (`uid`,`paswrd`) 
                                values('$uid','$paswrd')";
                               
$sql2=mysql_query($query2);
                               
echo "You are Successfuly Registered<br>";

mysql_close($link);
?>


---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
Login System



Here database name  “test4” and table name “user” and “user” fields name  (`uid`,`paswrd `)  

Login.php

<html>
<head>
<title>login</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="success.php">
  <table width="256" align="center">
    <tr>
      <td>User Id </td>
      <td><label>
        <input name="uid" type="text" id="uid" />
      </label></td>
    </tr>
    <tr>
      <td>Password</td>
      <td><label>
        <input name="pwd" type="password" id="pwd" />
      </label></td>
    </tr>
    <tr>
      <td colspan="2"><?php if(isset($_GET['i']))
                                                {
                                                                if($_GET['i']==1)
                                                                {
                                                                ?><span class="style3">Wrong Password or User Id....                                                  </span>                                                                <?php
                                                                }
                                                }
                                                ?>                          
                                                                </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label>
        <input type="submit" name="Submit" value="LOGIN" />
      </label></td>
    </tr>
  </table>
</form>
</body>
</html>

success.php

<?php
$link=mysql_connect("localhost","root","") or die ("Problem connecting to DataBase");
mysql_select_db("test4");
$user=trim($_POST['uid']);
$pass=trim($_POST['pwd']);

$sql=("select * from `user` where userid='$user' and passwd='$pass'");

$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1)
{
               
                                session_register("uid");
                                session_register("pwd");
                                header("location:samit1.php");
               
}
else
{
                header("location:login.php?i=1");
}
?>

samit1.php

<?php
session_start();
echo"Login Success";

?>
<html>
<body>
<form action="logout.php" method="post">
  <label>
  <input type="submit" name="Submit" value="LOGOUT">
  </label>
</form>
</body>
</html>

Logout.php
<?php
session_start();
session_destroy();
header("location:login.php");
?>


---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
Pass a value from one page to another page


form.php

<head>
<title>Untitled Document</title>

<style type="text/css">
<!--
.style1 {font-weight: bold}
.style2 {
                color: #990000;
                font-weight: bold;
}
-->
</style>
</head>

<body>
<form action="test.php" method="post" name="form1" id="form1">
  <table width="616" border="0" align="center">
    <tr>
      <td>&nbsp;</td>
      <td><span class="style2">FILLUP THE FORM </span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td width="115">&nbsp;</td>
      <td width="285">&nbsp;</td>
      <td width="202">&nbsp;</td>
    </tr>
  </table>
  <table width="581" border="0" align="center">
    <tr>
      <td width="112"><div align="right"><strong>Name : </strong></div></td>
      <td width="148"><label>
        <input name="name" type="text" id="name" value="First Name" />
      </label></td>
      <td width="250"><label></label></td>
      <td width="53">&nbsp;</td>
    </tr>
   
    <tr>
      <td><div align="right"><strong>Sex : </strong></div></td>
      <td><label>
        <select name="sex" id="sex">
          <option>-Select One-</option>
          <option>Male</option>
          <option>Female</option>
        </select>
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right"><strong>Email Id :</strong> </div></td>
      <td><input name="email" type="text" id="email" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right"><strong>Phone No : </strong></div></td>
      <td><input name="phno" type="text" id="phno" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right"><strong>Address : </strong></div></td>
      <td><input name="add" type="text" id="add" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right"><strong>Country : </strong></div></td>
      <td><label>
      <select name="country" id="country">
        <option>-Select One-</option>
        <option>Australia</option>
        <option>America</option>
        <option>France</option>
        <option>India</option>
        </select>
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <table width="459" border="0" align="center">
    <tr>
      <td width="49">&nbsp;</td>
      <td width="344"><label>
        <input type="submit" name="Submit" value="Submit" />
      </label></td>
      <td width="52">&nbsp;</td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <p align="left" class="style1">&nbsp;</p>
</form>
</body>
</html>

test.php

<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<?php
 echo "Name : ",$_REQUEST["name"],"<br/>";
 echo "Sex : ",$_REQUEST["sex"],"<br/>";
 echo "Email Id : ",$_REQUEST["email"],"<br/>";
 echo "Phone No : ",$_REQUEST["phno"],"<br/>";
 echo "Address : ",$_REQUEST["add"],"<br/>";
 echo "Country : ",$_REQUEST["country"],"<br/>";
  ?>
</body>
</html>





---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
Pass a value from one page to another page with confirmation

Here database name  “test5” and table name “user” and “user” fields (`name`,`sex`,`email`,`phno`,`add`,`country`) 



form.php

<html>
<head>
<title>Untitled Document</title>

<style type="text/css">
<!--
.style1 {font-weight: bold}
.style2 {
                color: #990000;
                font-weight: bold;
}
-->
</style>
</head>

<body>
<form action="test.php" method="post" name="form1" id="form1">
  <table width="616" border="0" align="center">
    <tr>
      <td>&nbsp;</td>
      <td><span class="style2">FILLUP THE FORM </span></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td width="115">&nbsp;</td>
      <td width="285">&nbsp;</td>
      <td width="202">&nbsp;</td>
    </tr>
  </table>
  <table width="581" border="0" align="center">
    <tr>
      <td width="112"><div align="right"><strong>Name : </strong></div></td>
      <td width="148"><label>
        <input name="name" type="text" id="name" value="First Name" />
      </label></td>
      <td width="250"><label></label></td>
      <td width="53">&nbsp;</td>
    </tr>
   
    <tr>
      <td><div align="right"><strong>Sex : </strong></div></td>
      <td><label>
        <select name="sex" id="sex">
          <option>-Select One-</option>
          <option>Male</option>
          <option>Female</option>
        </select>
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right"><strong>Email Id :</strong> </div></td>
      <td><input name="email" type="text" id="email" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right"><strong>Phone No : </strong></div></td>
      <td><input name="phno" type="text" id="phno" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right"><strong>Address : </strong></div></td>
      <td><input name="add" type="text" id="add" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right"><strong>Country : </strong></div></td>
      <td><label>
      <select name="country" id="country">
        <option>-Select One-</option>
        <option>Australia</option>
        <option>America</option>
        <option>France</option>
        <option>India</option>
        </select>
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <table width="459" border="0" align="center">
    <tr>
      <td width="49">&nbsp;</td>
      <td width="344"><label>
        <input type="submit" name="Submit" value="Submit" />
      </label></td>
      <td width="52">&nbsp;</td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <p align="left" class="style1">&nbsp;</p>
</form>
</body>
</html>

test.php
 
<html>
<head>
 <title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
                color: #990000;
                font-weight: bold;
}
-->
</style>
</head>
<body>
<p>
<?php
  $a=($_REQUEST['name']);
$b=($_REQUEST['sex']);
$c=($_REQUEST['email']);
$d=($_REQUEST['phno']);
$e=($_REQUEST['add']);
$f=($_REQUEST['country']);

  ?>
</p>
<form name="form2" method="post" action="insert.php">
  <label><br>
  </label>
  <table width="557" border="0" align="center">
    <tr>
      <td width="225">&nbsp;</td>
      <td width="137"><span class="style1">PRINT PREVIEW </span></td>
      <td width="181">&nbsp;</td>
    </tr>
  </table>
  <label><br>
  </label>
  <table width="290" border="0" align="center">
    <tr>
      <td width="104"><div align="right"><strong>Name : </strong></div></td>
      <td width="151"><label>
        <input name="name" type="text" id="name" value="<?php echo $a;?>"/>
      </label></td>
      <td width="21"><label></label></td>
    </tr>
    <tr>
      <td><div align="right"><strong>Sex : </strong></div></td>
      <td><label>
        <select name="sex" id="sex">
          <option><?php echo $b;?></option>
          <option>Male</option>
          <option>Female</option>
        </select>
      </label></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right"><strong>Email Id :</strong> </div></td>
      <td><input name="email" type="text" id="email" value="<?php echo $c;?>" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right"><strong>Phone No : </strong></div></td>
      <td><input name="phno" type="text" id="phno" value="<?php echo $d;?>" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right"><strong>Address : </strong></div></td>
      <td><input name="add" type="text" id="add" value="<?php echo $e;?>" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right"><strong>Country : </strong></div></td>
      <td><label>
        <select name="country" id="country">
          <option><?php echo $f;?></option>
          <option>Australia</option>
          <option>America</option>
          <option>France</option>
          <option>India</option>
        </select>
      </label></td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <table width="323" border="0" align="center">
    <tr>
      <td width="122">&nbsp;</td>
      <td width="191"><input type="submit" name="Submit2" value="I aggree"></td>
    </tr>
  </table>
</form>
<form name="form1" method="post" action="form.php">
  <table width="430" border="0" align="center">
    <tr>
      <td width="174">&nbsp;</td>
      <td width="246"><input type="submit" name="Submit" value="I don't aggree"></td>
    </tr>
  </table>
  <label></label>
</form>
<p>&nbsp;</p>
</body>
</html>

insert.php

<?php

$link=mysql_connect("localhost","root","") or die ("Problem connecting to DataBase");
mysql_select_db("test5");

$nm=($_REQUEST['name']);
$sx=($_REQUEST['sex']);
$em=($_REQUEST['email']);
$ph=($_REQUEST['phno']);
$ad=($_REQUEST['add']);
$cn=($_REQUEST['country']);

$query = "insert into `user`
                                (`name`,`sex`,`email`,`phno`,`add`,`country`) 
                                values('$nm','$sx','$em','$ph','$ad','$cn')";
                                                   
$sql=mysql_query($query);
                                                                               
echo "<h2>Successfuly Inserted Data</h2><br>";
               
mysql_close($link);
?>
------------------------------------------------------------------------------------------------------------------------------------



YOU WILL GET MORE TUTORIALS SOME DAYS LATER