PHP Tutorial With Practical Eaxmples

PHP (Pre Processor Hypertext)
I don't want to give, any theoretical  concept about PHP , because Practical things gives problems and I am trying to resolve those problems through some PHP scripts. These are very necessary scripts which  are helpful for creating any website.

OK ,

Without vesting any time let I start with connectivity:

When we are talking about connection, that means  there are more then one entities minimum two

such as in every every dynamic website need some database as a back end and some pages (interface) as a front end.

Now here we use PHP as a front end and MySQL as a back end.

Step1: Before writing connection script we must create database in MySQL. (example MyDataBase)

Step2: By using Macromedia Dreamweaver create a PHP page.

Step3: Write Connection String:
 


            <?php
                       $con = mysql_connect("localhost","root","pwd") or die(mysql_error());
                        mysql_select_db("MyDataBase",$con);
              ?>

write the above code  in one PHP  page and save it suppose name as "config.php"
If we want to fatch data from database then write following code:
here $sql is variable where all fatched data are stored.

<?php
include '
config.php';

$select_query = "SELECT * FROM table_name ";
$sql = mysql_query($select_query) or die(mysql_error()); 

?>   
Now display fatched data in HTML table.So for that first we create HTML table and write 
php code inside the table:
Example given below here we have 10 rows and 2 rows :
Save that page as displaydata.php

<table border="1" align="center"  bordercolor="#660000" bgcolor="#666600">
<tbody>


<?php
while($row = mysql_fetch_array($sql))
{
 echo"<tr>
    <td rowspan='11'><img src='{$row['images_path']}' width='100' heigth='200'/></td>
    <td>Name:</td>
    <td>{$row['name']}</td>
  </tr>
  <tr>
    <td>Father's Name:</td>
    <td>{$row['fname']}</td>
  </tr>
  <tr>
    <td>Age:</td>
    <td>{$row['age']}</td>
  </tr>
   <tr>
    <td>Height:</td>
    <td>{$row['height']}</td>
  </tr>
   <tr>
    <td>Color:</td>
    <td>{$row['color']}</td>
  </tr>
   <tr>
    <td>Education:</td>
    <td>{$row['education']}</td>
  </tr>
   <tr>
    <td>Profession:</td>
    <td>{$row['profession']}</td>
  </tr>
  <tr>
    <td>Income:</td>
    <td>{$row['income']}</td>
  </tr>

  <tr>
    <td>Address:</td>
    <td>{$row['address']}</td>
  </tr>
  <tr>
    <td>Contect:</td>
    <td>{$row['contact']}</td>
  </tr>
  <tr height='15'>
  <td colspan='3' bgcolor='#660000'></td>
</tr>

   \n";
  }
?>

  
</tbody></table>


For saving data to database write following code and save page as savedata.php
Example is given below:
Try to do it.
 
<?php
include 'config.php';
    
    $name=$_POST['txtname'];
    $fname=$_POST['txtfname'];
    $age=$_POST['txtage'];
    $height=$_POST['txtheight'];
    $color=$_POST['txtcolor'];
    $education=$_POST['txteducation'];
    $profession=$_POST['txtprofession'];
    $income=$_POST['txtincome'];
    $address=$_POST['txtaddress'];
    $contact=$_POST['txtcontact'];

     $query_upload="INSERT into marriagedata (name, fname, age, height, color, education,
profession, income, address, contact,) VALUES ('$name','$fname','$age','$height','$color','$education','$profession','$income','$address',
'$contact')";
    mysql_query($query_upload) or die("error in $query_upload == ----> ".mysql_error()); 

?>;

Upload Soon....

2 comments: