PHP Project-5: Counter script tutorial

Posted: November 7, 2010 in MySql, PHP
Tags: ,

In this tutorial create 1 file
1. counter.php

1. Create table “counter” in database “test”.
2. Create file counter.php.

1. Create table “counter”

CREATE TABLE `counter` (
`counter` int(9) NOT NULL default '0'

2. Create file counter.php


$host="localhost";  // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select database.
mysql_connect("$host",  "$username", "$password")or die("cannot connect to server ");
mysql_select_db("$db_name")or die("cannot select DB")

$sql="SELECT  * FROM $tbl_name";


// if have no counter value set counter = 1
$sql1="INSERT INTO  $tbl_name(counter) VALUES('$counter')";

echo  "You 're visitors No. ";
echo $counter;

// count  more value
$sql2="update  $tbl_name set counter='$addcounter'";


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s