machan mata podi script ekak hamba una
mata one data insert karanna
html form ekain data mysqli walata yana widihata
mata poddak karana widiha kiyanna
DB
CREATE TABLE `banners` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`url` VARCHAR( 150 ) NOT NULL ,
`banner` VARCHAR( 150 ) NOT NULL ,
`name` VARCHAR( 60 ) NOT NULL, 'clicks' INT NOT NULL DEFAULT '0'
) ;
conection
<?php $db_host = "localhost";
$db_username = "root";
$db_password = "";
$db_database = "counter";
$link = mysqli_connect($db_host,$db_username,$db_password) or die("Cannot connect");
mysqli_select_db($link, $db_database) or die("Cannot select the database"); ?>
index
<?php
include("config.php");
$sql = mysqli_query($link, "SELECT id, url, banner, name FROM banner");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>banners index page</title>
</head>
<body>
<div id="container">
<?php
while($result = mysqli_fetch_object($sql)):
?>
<p>
<a href="counter.php?id=<?php echo $result->id; ?>">
<img src="<?php echo $result->banner; ?>" alt="<?php echo $result->name; ?>" />
</a>
</p>
<?php
endwhile;
?>
</div><!-- end of container -->
</body>
</html>
count
<?php
//1. include the configuration file
include("config.php");
//2. Get the id from the url and store it into a variable
$id = mysqli_real_escape_string($link, $_GET['id']);
//3. fetch the url and clicks from this banner
$clicks = mysqli_fetch_object(mysqli_query($link, "SELECT url, clicks FROM banners WHERE id=".$id.""));
//4. increase clicks with 1
$new_click = $clicks->clicks+1;
//5. update this into the database, check if it was succesfull
if(mysqli_query($link, "UPDATE banners SET clicks=".$new_click." WHERE id=".$id."")):
//6. redirect to the url
header("Location: ".$clicks->url);
else:
//6. else write to error log
endif;
?>
mata one data insert karanna
html form ekain data mysqli walata yana widihata
mata poddak karana widiha kiyanna
DB
CREATE TABLE `banners` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`url` VARCHAR( 150 ) NOT NULL ,
`banner` VARCHAR( 150 ) NOT NULL ,
`name` VARCHAR( 60 ) NOT NULL, 'clicks' INT NOT NULL DEFAULT '0'
) ;
conection
<?php $db_host = "localhost";
$db_username = "root";
$db_password = "";
$db_database = "counter";
$link = mysqli_connect($db_host,$db_username,$db_password) or die("Cannot connect");
mysqli_select_db($link, $db_database) or die("Cannot select the database"); ?>
index
<?php
include("config.php");
$sql = mysqli_query($link, "SELECT id, url, banner, name FROM banner");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>banners index page</title>
</head>
<body>
<div id="container">
<?php
while($result = mysqli_fetch_object($sql)):
?>
<p>
<a href="counter.php?id=<?php echo $result->id; ?>">
<img src="<?php echo $result->banner; ?>" alt="<?php echo $result->name; ?>" />
</a>
</p>
<?php
endwhile;
?>
</div><!-- end of container -->
</body>
</html>
count
<?php
//1. include the configuration file
include("config.php");
//2. Get the id from the url and store it into a variable
$id = mysqli_real_escape_string($link, $_GET['id']);
//3. fetch the url and clicks from this banner
$clicks = mysqli_fetch_object(mysqli_query($link, "SELECT url, clicks FROM banners WHERE id=".$id.""));
//4. increase clicks with 1
$new_click = $clicks->clicks+1;
//5. update this into the database, check if it was succesfull
if(mysqli_query($link, "UPDATE banners SET clicks=".$new_click." WHERE id=".$id."")):
//6. redirect to the url
header("Location: ".$clicks->url);
else:
//6. else write to error log
endif;
?>
