How to Create Web Page Using PHP

Introduction

In this article I will explain creation of a dynamic web page using PHP. To create a dynamic web page, first of all you will create a database, table and a session. You will then use this code to create a dynamic web page.

website.jpg

Example

<?php

session_start();

function web()

{

$dbc = mysql_connect("localhost","root","");

mysql_select_db("examples");

return $dbc;

}

function getMaxId()

{

$dbc = web();

$query = mysql_query("SELECT MAX(id) FROM `dynamicphpmysql`");

$results = mysql_fetch_array($query);

$new_id = $results['MAX(id)'];

mysql_close($dbc);

return $new_id;

}

function newId()

{

$dbc = web();

mysql_query("INSERT INTO dynamicphpmysql(visits) VALUES(0)");

mysql_close($dbc);

$new_id = getMaxId();

return $new_id;

}

function newVisit($id)

{

$dbc = web();

mysql_query("UPDATE dynamicphpmysql SET `visits` = `visits` + 1 WHERE id = $id");

$result = mysql_query("SELECT `visits` FROM dynamicphpmysql WHERE `id` = $id");

$new_count = mysql_result($result,0);

mysql_close($dbc);

return $new_count;

}

if(!isset($_SESSION['id']))

{

newid();

$_SESSION['id'] = getMaxId();

echo "This is your first visit to this page.";

}else{

$num_visits = newVisit($_SESSION['id']);

echo "You have visited this page $num_visits times before.";

}

?>

Output

website2jpg.jpg

Your visited site count in your table, such as:

website1.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all