Reputation: 608
I tried to add a hit counter to my actual website so that I can order the offers by no. of hits. I don't get any kinda error but my database is not updating as I want it to and I have a clue why but I can't seem to solve the problem.
This is how I add the offer in my database.
if (isset($_POST['add']))
{
require_once("mysql_connect.php");
$id=uniqid();
$email=$_SESSION['email'];
$denumire_locatie=$_POST['denumire_locatie'];
$tip_locatie=$_POST['categorie'];
$judet=$_POST['judet'];
$localitate=$_POST['localitate'];
$strada=$_POST['strada'];
$numar=$_POST['numar'];
$telefon=$_POST['telefon'];
$fax=$_POST['fax'];
$descriere=$_POST['descriere'];
$data_modificare=date("Y/m/d H:i:s", time() + 3600);
$adresa_ofertei="oferta.php?id=['id_oferta']";
$query="INSERT INTO oferte VALUES ('" . $id ."', '$email', '$denumire_locatie','$tip_locatie', '$judet', '$localitate', '$strada', '$numar','$telefon', '$fax', '$descriere','$id', '$data_modificare', '$adresa_ofertei')";
mysql_query($query) or die (mysql_error());
I think that the problem occurs in the variable "adresa_ofertei" because when I added that line of code (and updated the query) I couldn't add offers anymore. Basically what I want is that when an offer is added to automatically generate a link based on the id of that entry and add it to MySQL so I can use it in my dynamic generated pages like this:
<?php
$adresa_ofertei = $_SERVER['PHP_SELF'];
$sql = "UPDATE oferte SET accesari=accesari+1 WHERE adresa_ofertei='$adresa_ofertei' LIMIT 1";
$res = mysql_query($sql);
?>
In case it helps "adresa_ofertei" means "offer_address" and "accesari" means "hits". I already double checked my database and my code for any typos so that's probably not the problem. Please try to answer in such way that it won't only resolve my current problem but help me and the others understand how to make a hit counter based on dynamic pages. Thank you very much and let me know if I have to modify my question in any way before downrating since I'm kinda new to both PHP and Stack Overflow.
Upvotes: 2
Views: 643
Reputation: 2408
I think these two points should help you resolve the problem.
Upvotes: 2