danlew Posted July 6, 2006 Share Posted July 6, 2006 My first time here & I am trying to develop a click counter that counts individual customers websites hit and leaves a count next to there click website icon,I ONLY KNOW THE BASICS OF PHP & MYSQL and i have created some PHP files & a MYSQL database which i have not yet completed the MYSQL database will be INT or BIGINT to store millions of numerical values. ( I Believe )I would like when anybody hits this link for example - www.mywebsite/hit/click.php?id=1 it will go to address www.mycustomer.com than i will need to have a databse to store the website addresses or id no's? for example www.mywebsite/hit/click.php?id=1 - www.mycustomer.com for example www.mywebsite/hit/click.php?id=2 - www.anothercustomer.com how do iset the database to enter this??? also.... in PHP i have designed about 7 files all hopefully communicating with mysql the way its meant to? i can also show you these files if i run into troubles which im more than likely going to. and than lastly..... i will have the html files that contain the websites of my customers, with an click icon, when they click on the icon it will read just next to it the no. of times its been hit. the way ive done that is put the click button link to address: ww.mywebsite/hit/click.php?id=1 for example than it gets redirected to the website www.mycustomer.com and no of clicks also gets stored either in a txt.file ar database in which i assume is most likely the case. Hope this all makes sense, and have some body help me with this,thanks very much Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/ Share on other sites More sharing options...
hackerkts Posted July 6, 2006 Share Posted July 6, 2006 Modify to your needs[code] <?php if(!empty($_GET['file'])) { $id = $_GET['file']; function go_to_file($id) { $dl_query = "SELECT * from counter WHERE id ='$id'"; $dl_result = mysql_query($dl_query) or die("Query failed: " . mysql_error()); $dl_row = mysql_fetch_array($dl_result); $id = $dl_row['id']; $FileName = $dl_row['FileName']; $FileURL = $dl_row['FileURL']; $Count = $dl_row['Count']; $go = "<META HTTP-EQUIV='refresh' CONTENT='0;URL=". $FileURL ."'>"; $dl_query = "UPDATE counter SET Count=Count+1 WHERE id='$id'"; $dl_result = mysql_query($dl_query) or die("Query failed: " . mysql_error()); return $go; } echo go_to_file($id); } ?>[/code]Datebase:[quote]CREATE TABLE `counter` ( `id` int(5) NOT NULL auto_increment, `FileName` varchar(50) NOT NULL, `FileURL` varchar(255) NOT NULL, `Count` int(5) NOT NULL, PRIMARY KEY (`id`))[/quote]If you need more explainations feel free to ask. Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-53763 Share on other sites More sharing options...
danlew Posted July 6, 2006 Author Share Posted July 6, 2006 WOW! So this all seems easier than what i thought,does this mean its just simply 1 php file (index.php) i have the following[table][tr][td]<?php mysql_connect("<MYHOSTNAME", "USER","PASSWORD") or die(mysql_error()); mysql_select_db("COUNTER") or die(mysql_error()); $data = mysql_query("SELECT * FROM friends") or die(mysql_error()); <?phpif(!empty($_GET['file'])) { $id = $_GET['file']; function go_to_file($id) { $dl_query = "SELECT * from counter WHERE id ='$id'"; $dl_result = mysql_query($dl_query) or die("Query failed: " . mysql_error()); $dl_row = mysql_fetch_array($dl_result); $id = $dl_row['id']; $FileName = $dl_row['FileName']; $FileURL = $dl_row['FileURL']; $Count = $dl_row['Count']; $go = "<META HTTP-EQUIV='refresh' CONTENT='0;URL=". $FileURL ."'>"; $dl_query = "UPDATE counter SET Count=Count+1 WHERE id='$id'"; $dl_result = mysql_query($dl_query) or die("Query failed: " . mysql_error()); return $go; } echo go_to_file($id); } ?>[/table]AND WITH MYSQLwhen i insert what would go in the following?ID: 1 etc.FILE NAME: books.htmlFILE URL: www.clientswebsite.com or www.mywebsite.com/click/id1.phpAND WITH MY WEBPAGESWHERE IN MY WEBPAGES DO I ENTER A SCRIPT FOR IT TO READ THE DATABASE AND PHP FILE Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-53799 Share on other sites More sharing options...
hackerkts Posted July 6, 2006 Share Posted July 6, 2006 -_-! You last 2 lines should use capital letters.ID you just ignore them, it will auto increase by 1, File name is actually the Site name and the FileURL is actually the page url.It depends where you want this script to work,ok let's say if you save it as index.phpThen you can access it by going to [b]http://domain/index.php?file=1[/b] It will redirects you to your FileURL index 1.P.S: I think you should change the $_GET['file'] to $_GET['page'] so it will be page=1 instead of file=1 Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-53819 Share on other sites More sharing options...
danlew Posted July 7, 2006 Author Share Posted July 7, 2006 Great, so is this how it would be when i go to insert in mYSQL?for example?File URL: www.mywebsite.comFile Name: www.customerswebsite.comFile URL: www.mywebsite.comFile Name: www.anothercustomerswebsite.comIs this right?and.......Is it possible to have another php file to add data to for it to get stored into MYSQL? so i dont have to enter in MYSQL, and what is the best way to code the other php file. than i just enter data as a webform do i? for example www.mywebsite/adddata.php.Thanks very much Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54237 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 [code]<?phpif (!isset($_POST['submit'])) {?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div> Page Name: <input type="text" name="name" style="width:120px; height:18px; font-family:Tahoma; font-size:11px "><br> Page URL: <input type="text" name="url" style="width:120px; height:18px; font-family:Tahoma; font-size:11px "> <input type="submit" name="submit" value="Submit"> </div> </form><?php} else { $name = $_POST['name']; $url = $_POST['url']; if ($name == "" || $url == "") { echo "Please fill up all the blanks."; } else { mysql_query("INSERT INTO `counter` VALUES ('', '$name', '$url', '0')") or die ("There's some problem inserting the informations."); echo "You have successfully insert the informations."; } }?>[/code][b][color=red]Note[/color][/b]: If you just use the scripts above, anyone can enter the informations into database. You need to modify alittle more to ensure only user with permission can enter it. :D Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54244 Share on other sites More sharing options...
danlew Posted July 7, 2006 Author Share Posted July 7, 2006 I just named the file adddata.php and just edited the top as follows;<?phpif (!isset($_POST['submit'])) {?> <FORM name=senddata action=./adddata.php method=post> <div> Page Name: <input type="text" name="name" style="width:120px; height:18px; font-family:Tahoma; font-size:11px "><br> Page URL: <input type="text" name="url" style="width:120px; height:18px; font-family:Tahoma; font-size:11px "> <input type="submit" name="submit" value="Submit"> </div> </form><?php} else { $name = $_POST['name']; $url = $_POST['url']; if ($name == "" || $url == "") { echo "Please fill up all the blanks."; } else { mysql_query("INSERT INTO `counter` VALUES ('', '$name', '$url', '0')") or die ("There's some problem inserting the informations."); echo "You have successfully insert the informations."; } }?>BUT!!!!!It gives me a error like this;mysql_query(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /home/content/t/h/a/website/html/hitcounter/adddata.php on line 18 Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54257 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 Lolz :PI fogotten to tells you to add connection to your MySQL.Add this below [b]<?[/b][code]$host = "localhost";$username = "root";$password = "";$db = "database";mysql_connect($host,$username,$password) or die(mysql_error());mysql_select_db($db) or die(mysql_error());[/code]Remeber to change the config. Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54259 Share on other sites More sharing options...
danlew Posted July 7, 2006 Author Share Posted July 7, 2006 Ok, The adddata form seems to work now, i would also like the option of find / switch to edit - idalso.......i just did a testfrom one of my webpages to click on http://www.mywebsite/hitcounter/click.php?id=1and it gave me errorParse error: parse error, unexpected '<' in /home/content/t/h/a/mywebsite/html/hitcounter/click.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54264 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 I assume your click.php contains:[code]<?phpmysql_connect("<MYHOSTNAME", "USER","PASSWORD") or die(mysql_error());mysql_select_db("COUNTER") or die(mysql_error());$data = mysql_query("SELECT * FROM friends")or die(mysql_error());<?phpif(!empty($_GET['file'])) { $id = $_GET['file']; function go_to_file($id) { $dl_query = "SELECT * from counter WHERE id ='$id'"; $dl_result = mysql_query($dl_query) or die("Query failed: " . mysql_error()); $dl_row = mysql_fetch_array($dl_result); $id = $dl_row['id']; $FileName = $dl_row['FileName']; $FileURL = $dl_row['FileURL']; $Count = $dl_row['Count']; $go = "<META HTTP-EQUIV='refresh' CONTENT='0;URL=". $FileURL ."'>"; $dl_query = "UPDATE counter SET Count=Count+1 WHERE id='$id'"; $dl_result = mysql_query($dl_query) or die("Query failed: " . mysql_error()); return $go; } echo go_to_file($id); } ?>[/code]Go to line 6 and remove [b]<?php[/b] Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54267 Share on other sites More sharing options...
danlew Posted July 7, 2006 Author Share Posted July 7, 2006 we are nearlly there..... i think :Psilly me i had removed line 6 ( <?php ) [b]now i get a different error message when i click and test the link....Table 'backtobasics.friends' doesn't exist[/b] Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54269 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 Sorry for the late reply, was writing a script for someone.Hmm... Check your database, you don't have the table [b]friends[/b] Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54273 Share on other sites More sharing options...
danlew Posted July 7, 2006 Author Share Posted July 7, 2006 I accidently copied this line from another php scrip i had$data = mysql_query("SELECT * FROM friends") can i just delete friends, i dont have a table called friends? and what do i replace the "friends with? Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54275 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 Remove[code]$data = mysql_query("SELECT * FROM friends")or die(mysql_error());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54280 Share on other sites More sharing options...
danlew Posted July 7, 2006 Author Share Posted July 7, 2006 I have now removed that,than when i click the link to go to http://www.mywebpage.com/hitcounter/click.php?id=1it just gives me a blank page Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54285 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 Have you put something into database ? Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54287 Share on other sites More sharing options...
danlew Posted July 7, 2006 Author Share Posted July 7, 2006 Thankyou for your quick response/s,Ok currently i am experiencing difficulty getting my php admin / mysql access page to load,it keeps on timing outi will hopefully sort this out and get back to you once this has resolved,or in another case could be the reason as to why its showing blank. Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54293 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 Don't worry about that, take your time. :P Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54298 Share on other sites More sharing options...
danlew Posted July 7, 2006 Author Share Posted July 7, 2006 Ok, 5 hours later i resolved the php/mysql admin issue with my host,Scarey stuff, huh, as well as back up all my other databases..........................................................................................When i click on the link it now seems to be directing/going to the appropriate website url i allocate. wihich is great, (well done!)but..It doesnt show the hit count display (no. of times being clicked in simple text display ) next to the icon i click? Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54370 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 Do you have a live demo ? I wanna see where you wanna put it at. Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54397 Share on other sites More sharing options...
danlew Posted July 8, 2006 Author Share Posted July 8, 2006 Sure can i PM it to you? Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54669 Share on other sites More sharing options...
hackerkts Posted July 8, 2006 Share Posted July 8, 2006 Yeah, no problem.[b]Edit[/b]: I guess the problem is solve. ;) Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54670 Share on other sites More sharing options...
danlew Posted July 8, 2006 Author Share Posted July 8, 2006 This forum is the best forum ive seen, with the most helpful experts around,not to mention : hackerktsI couldnt have been taken care of any better any where else,fast response, easy solutions, and dedicated customer service.unbeatable...............and one extrememly happy webdeveloper ;D Quote Link to comment https://forums.phpfreaks.com/topic/13827-click-counter/#findComment-54698 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.