1. This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
    For information on cookies and how you can disable them visit our Cookie Usage page.
    Dismiss Notice

PHP Simple Text PHP Counter for website!

Discussion in 'Web Development' started by Mir Ahmad, Jul 31, 2013.

  1. Mir Ahmad

    Mir Ahmad New Member

    Hi
    I am new in web designing but little effort for those who new like me, this my first thread hope all like and reply my new post! thanks in advance!


    <?php

    $host="hostname"; // Host name
    $username="sqlusername"; // Mysql username
    $password="sqlpass"; // Mysql password
    $db_name="db_name"; // Database name
    $tbl_name="table_name"; // 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";
    $result=mysql_query($sql);
    $rows=mysql_fetch_array($result);
    $counter=$rows['counter'];

    // if have no counter value set counter = 1
    if(empty($counter)){
    $counter=1;
    $sql1="INSERT INTO $tbl_name(counter) VALUES('$counter')";
    $result1=mysql_query($sql1);
    }
    //<font size="2">
    <font face="verdana">
    echo "Total Visitors. ";
    echo $counter;

    // count more value
    $addcounter=$counter+1;
    $sql2="update $tbl_name set counter='$addcounter'";
    $result2=mysql_query($sql2);

    mysql_close();
    ?>
     
  2. Ruthe

    Ruthe Community Manager

    Thanks for sharing that with us Mir! (Do I call you that? Or Ahmad?) It's a breath of fresh air to see new posters helping out as well :LOL: