The PHP Group PHP Logo
Posted on Mar 19, 2009

Php counter im trying to add a visitor counter to my homepage i downloaded the script but not sure what to do and where to put things to get it running this is the counter script... // 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'') $tbl_name=''counter''; // Table name $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); } echo ''You 're visitors No.'' echo $counter; // count more value $addcounter=$counter+1; $sql2=''update $tbl_name set counter='$addcounter'''; $result2=mysql_query($sql2); mysql_close(); ?> and this is mode homepage code.. LOGIN Wanna find out all the latest upto date infomation on the AbZoRbeD network, Then check this out. Dont idle for no reason join in the game and have a little fun battling against the other players. Use this forum for discussing all kinds of topics you must be registered and logged in to access this area if you would like to register Click Here Contact Us © AbZoRbeD.net 2007-2009 any help would be grate :)

  • 1 more comment 
  • d_howley Mar 19, 2009

    sorry i forgot to say that i have that all setup

    just didnt want my username and password getting out :)

  • d_howley Mar 20, 2009

    should the path to the counter.php go in here i got the counter.php in a folder called counter because i keep getting the error ... PHP Fatal error: Call to undefined function counter()

  • d_howley Mar 20, 2009

    i did what you said now im just getting an error .... Fatal error: Call to undefined function counter()

×

2 Answers

Anonymous

Level 1:

An expert who has achieved level 1.

Mayor:

An expert whose answer got voted for 2 times.

  • Contributor 4 Answers
  • Posted on May 09, 2009
Anonymous
Contributor
Level 1:

An expert who has achieved level 1.

Mayor:

An expert whose answer got voted for 2 times.

Joined: May 09, 2009
Answers
4
Questions
0
Helped
14606
Points
9

You might want to note that this is not the most effective manner of creating a counter in PHP. On a few of my websites, I find it is much more effective to simply create a text file, eg. counter.txt and have PHP read that every time the page is loaded, instead of running a MySQL query. Then, have PHP also update the counter.txt file by adding 1 to the number already listed in the file and read to the user.

Dubravko

Level 1:

An expert who has achieved level 1.

Corporal:

An expert that has over 10 points.

Problem Solver:

An expert who has answered 5 questions.

  • Contributor 10 Answers
  • Posted on Mar 19, 2009
Dubravko
Contributor
Level 1:

An expert who has achieved level 1.

Corporal:

An expert that has over 10 points.

Problem Solver:

An expert who has answered 5 questions.

Joined: Mar 19, 2009
Answers
10
Questions
0
Helped
15696
Points
12

These lines

mysql_connect(''$host'', ''$username'', ''$password'')or die(''cannot connect to server '');
mysql_select_db(''$db_name'')or die(''cannot select DB'')
$tbl_name=''counter''; // Table name
$sql=''SELECT * FROM $tbl_name'';

say that you need mysql database. user name, password and table in that database called counter....

So if you do please change parameters if you don't, dont yuse this script, use just some site with free simple counter for your site, which is maintained on their site

  • Dubravko Mar 19, 2009

    Then, the best way is to wrap it into some function, include that code in homepage and call function from somewhere in page where you want it to be seen , for ex.


    function counter()
    {
    //copy counter code here
    }
    ?>.....



    ....




  • Dubravko Mar 20, 2009

    See this page for includes, don't change function call.

    http://www.w3schools.com/PHP/php_include...

    in your case




×

Ad

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

0helpful
1answer

My computer freezes up and the message "Warning: Unresponsive Script" appears in a box. It gives me 3 choices, debug, stop script,continue all of which I've tried and none of which work.

stop the script, script allow people track you, my recommended advice, go to the security settings, than goto advanced section and if you have an option to restore advanced settings, reset to default, do that, than security options look for custom level, open look at every thing you want to access or allow script to run your computer.
script puts all those pop up ads in the internet, track your buying habits, every site you visit, look for internet provider, look in the manage you add-on programs install programs fight the script,call GET ADD-ON, read each one select the one you want and dont use the ones you do not want, i use GREASEMONKEY, ADBLOCKPLUS, FIREFTP, COOKIECONTROL, LEECHBLOCK,
all the strick access for script,
5helpful
4answers

What is java script

Java script is a program that works with other programs such as Adobe Flash Player and many others to procees and enable you to read and store items. You can get Java here;
http://www.java.com/en/
If you were trying to watch YouTube you would have to have Java and a Flash Player in order for your system to process and play the video. I f you need Flash Player you can get that here;
http://get.adobe.com/flashplayer/
You have to make sure you have no prior versions of either of these products so, check in device manager and make sure you don't have prior versions. If you do, unistall the prior versions before download od new versions.
0helpful
1answer

How do i use the webcom

If you are talking about WebCom Graphic Access Counter - then the things are easy.
Basically it's about inserting a HTML tag in your page to generate a counter (for the visitors or any other purposes).
The simplest counter will look like this:
<IMG SRC="/counter">
To insert this counter in your web page you have to EDIT the HTML code that henerates the web page you are talking about.
0helpful
1answer

I am using vista business on my laptop and I can't get past the initializing download screen. Please help!!

Please ensure your firewall is not blocking Skype. Simply check on your control pannel what firewall is allowing and blocking, find out what the download files called add it to the allow section.
If that doesn't work try this Visual Basic Script (VBScript) is not installed or has been disabled. Make sure VBScript is installed, turn off script blocking in anti-virus and personal firewall software, reregister VBScript, and then run the installation again.
Mar 07, 2010 • Skype IM
0helpful
1answer

How to recover apache?

This page may help you out. http://www.easyphp.org/introduction.php

For my server, I use http://www.php.net/downloads.php. It works well without any problems.

In your Apache httpd.conf file add this script at the very end:
</IfModule>
#
#load the php main library to avoid dll mistakes
Loadfile "C:\Program Files\php5ts.dll"
#load the sapi so that apache can use php
LoadModule php5_module "C:\Program Files\php5apache2_2.dll"
#set the php.ini location so that you don't have to waste time guessing where it is
PHPIniDir "C:\Program Files\"
#Hook the php file extensions, notice that Addtype is NOT USED, since it isn't needed
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps
0helpful
1answer

My business site - need flash files to play for all visitors

Did you move the directory of any of the files? If not, then make sure you aren't using ActiveX Controls, because Microsoft created it and it only works with Microsoft. Did the Mac you used have flash player installed and up to date? The only thing i can think of is to include a download link for the flash player and make sure it isnt using ActiveX.
1helpful
2answers

Logout script with session management in php5

just create a logout.php script with the following

<?php
session_start();
session_destroy();

header("Location: index.php");
?>

Have your logout button/link/whatever just open that page which connects to the session with session_start. Session destroy does exactly what it sounds like... it unsets all session data and tells the server to end the session. The header request then just re-directs the user to whatever page you want after (just change out index.php)
0helpful
1answer

PHP Troubleshooting

Most often the problem is caused by loops in your PHP. One common mistake is to forget to actually ++ add to the counter at the end of a loop, so your loop will continue to run forever. Another common mistake is that, you do add to the counter, but then accidently overwrite it again at the start of the next loop, so you never gain any ground.
Depending on what your loops is doing, this can cause your script to continue to output the same information over and over again (continuing to make the page longer and longer and longer) or it can keep processing the same information over and over without outputting anything giving it the appearance of a page that is trying to load but is lagging.

One way to help you spot this is to echo () the current counter number (or other useful information) at the beginning of each cycle. This way you might get a better idea of where the loop is tripping up.

If you're not using loops, you may want to double check that any HTML or JAVA you are using on your page isn't causing the problem, and that any included pages are without error.
0helpful
1answer

Java script

hi,

Im sure there is a problem with ur browser software... Try to Reinstall the browser software r change the browser software.

thanks.
Not finding what you are looking for?

13,412 views

Ask a Question

Usually answered in minutes!

Top The PHP Group Computers & Internet Experts

Grand Canyon Tech
Grand Canyon Tech

Level 3 Expert

3867 Answers

Brad Brown

Level 3 Expert

19187 Answers

Cindy Wells

Level 3 Expert

6688 Answers

Are you a The PHP Group Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...