Your Ad Here

 Navigation
Home
Source code
Tutorials
RSS feeds
Articles
Wordpress plugins
Blog
Books
Software
Downloads
Hosting
manuals
Script directory
Training
Our Links




 Sponsors
 Links
software directory
dvd information
golfing products
 Downloads
 Misc
Webmaster Resources
Only PHP
ScriptSearch.com
Scripts.com - Get the best scripts NOW!
AndreaPHP Programming

Valid XHTML 1.0 Transitional


Valid CSS!


Log stats part 2


Log stats

Welcome to the second part of this mini tutorial / code snippet . Now we will log some info to our MySQL database using PHP .

Here is the script we are using , you will have to input ypour own host , username and password for this to operate correctly.

<?php
//store the users browser in a variable
$users_browser = $HTTP_USER_AGENT;
//store the users IP in a variable
$users_ip = $REMOTE_ADDR;
//database connection
$connection = mysql_connect("localhost" , "username" , "password");
//select the stats database
mysql_select_db("stats" , $connection);
//insert the info into the stats table
$sql_query = "INSERT INTO stats(browser,ip,logdate)
VALUES('$users_browser','$users_ip',now())";
//store
$result = mysql_query($sql_query);
?>

Now all we have to do is test the script works correctly , save the above and call it something like logstats.php , now load this page into your web browser , if you have more than one different make of browser that is even better .

Now go back to MySQL command line and type in the following

SELECT * FROM stats;

If all has gone to plan you should now see an entry in your table , here is a screen capture of what we had displayed.

Note this is only part of the table that was displayed but as you can see it has logged 2 different browsers Internet Explorer 5.5 and Opera 5 as well.

In the next part we will show how to display the results in an HTML table in your browser.

Back to Part 1 , Forward to Part 3




Books
 Sponsors
 Random Code
Simple email sender(internet)
Output a number with leading zeroes(math)
A daily MySQL row displayed(database)
 Random Article
  Network
Programming resources
Tutorials directory
Clickbank mall
sell software
Free auctions, low cost stores
UK products
US products
Gambling directory
Sexy free wallpapers
Hosting resources
ASP site
DVD site
Domain names
Dating site
Software directory
Maxi directory
bigarticle : free articles




beginners PHP Copyright © 2004 onwards by beginnersPHP.