Solved

update mysql field on click?

Posted on 2010-08-12
11
322 Views
Last Modified: 2013-12-13
I want to update a specific field in a specific row in a database using php...

i.e. when <a href="index.html>Home</a> is clicked it adds 1 to a running tally in:
Database - exampledatabase
table - exampletable
Where row = example record
in Field = hit_count

Any Ideas?
0
Comment
Question by:maccaj51
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 11

Accepted Solution

by:
Pieter Jordaan earned 500 total points
ID: 33421505

If you link to index.html the page will just count every time it is read, so you can add the code anywhere.

<?php
 mysql_query("update tablename set field = field + 1 where condition");
?>
0
 

Author Comment

by:maccaj51
ID: 33421578
so:

<?php
$con = mysql_connect("localhost","USERNAME","PASSWORD");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("DBNAME", $con);
mysql_query("update TABLENAME set PAGECOUNT = field + 1 where condition");
?>

Would this be right?!
0
 
LVL 11

Expert Comment

by:Pieter Jordaan
ID: 33421652
It depends on your table layout.
If there is only one field, use
 update TABLENAME set PAGECOUNT = PAGECOUNT + 1

Or use your primary key.
 update TABLENAME set PAGECOUNT = PAGECOUNT + 1 where id=1
0
 
LVL 11

Expert Comment

by:Pieter Jordaan
ID: 33427850

Do you still require assistance with this Question?
0
 

Author Comment

by:maccaj51
ID: 33428948
Hi BitFreeze...

So sorry been snowed under... havent tried it yet!

But will get back to you and will accredit you as necessary!!

Maccaj51
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 108

Expert Comment

by:Ray Paseur
ID: 33437062
It sounds like the thing you're looking for is called a "page hit counter" and you might get better results if you used the Google Analytics web service -- instead of trying to write one yourself.

But that said, here are some resources that describe how it is done ;-)
http://www.lmgtfy.com?q=php+page+hit+counter
0
 

Author Comment

by:maccaj51
ID: 33445175
BitFreeze....

This is my code... But doesnt seem to be working or incrementing on page view...?  

<?php
mysql_query("update news set PAGECOUNT = PAGECOUNT + 1 where filename=$filename");
?>
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 33445217
Try first solution posted by BitFreeze in post id ID:33421505

<?php
 mysql_query("update tablename set hit_count = hit_count + 1 where examplerecord = '' ");
?>

You have only to add the correct condition to identify row wich has to be updated.

Bye
0
 
LVL 11

Expert Comment

by:Pieter Jordaan
ID: 33445235

So your MySQL field has "filename" as the Primary ?
Please post the table layout.
0
 

Author Closing Comment

by:maccaj51
ID: 33445268
Im being very slow haha! BitFreeze ur first post has worked!! BRILLIANT!!

Thanks to marqusG: for pointing out my ineptitude!!
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 33445390
Sorry, but if so you could assign an assited solution to my comment, don't you?
Kind regards
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP Healthcheck 2 83
.php tree directory? 5 55
converting numbers with php 3 27
simple shopping cart database structure 5 28
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now