Forums
This topic is locked
Update record field without form
19 Dec 2003 07:17:37 Mike Man posted:
How to write a code that every time a page loads, it update automatically a record field in mysql databse?I have a table with counter as a INT field. Now I want to update this counter field with increment +1 everytime the page laods. Could anyone please help me?
Replies
Replied 04 Jan 2004 09:32:16
04 Jan 2004 09:32:16 Niclas Meyer replied:
make a file: functions.php
in functions.php write:
<?php
function counterAdd(){
$SQL="UPDATE yourTable SET counter=counter+1 (or counter++)";
$query=mysql_query($SQL) or die (mysql_error("update went bad");
}
?>
add this at page top:
<?
require_once('functions.php');
counterAdd();
?>
in functions.php write:
<?php
function counterAdd(){
$SQL="UPDATE yourTable SET counter=counter+1 (or counter++)";
$query=mysql_query($SQL) or die (mysql_error("update went bad");
}
?>
add this at page top:
<?
require_once('functions.php');
counterAdd();
?>