I've problem of my click counter program. I want to stop running on pressing F5 or page refresh in browser which already connects with phpmyadmin database and i want it works when button click only...
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="mypage"; // Database name
$tbl_name="counter"; // Table name
$message = "offer End";
// 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");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
$counter=$rows['visitors'];
// if have no counter value set counter = 1
if(empty($counter))
{
$counter=1;
$sql1="INSERT INTO $tbl_name(visitors) VALUES('$counter')";
$result1=mysql_query($sql1);
}
if($counter>1)
{
// count more value
$addcounter=$counter-1;
$sql2="update $tbl_name set visitors='$addcounter'";
$result2=mysql_query($sql2);
echo "You 're visitors No. ";
echo $addcounter;
mysql_close();
}
else
{
//$counter=0;
echo "<script type='text/javascript'>alert('$message');</script>";
mysql_close();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="POST" action="">
<input type="submit" name="insert" value="submit" onclick="" />
</form>
</body>
</html>
See Question&Answers more detail:os