Incrémentation de compteur
Bonjour,
j'ai un probleme avec mon compteur qui incremente a chaque fois la totalite de ma table "counter" et non pas juste l'article en question.
Je vous livre mon bout de code php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| $conn = mysql_connect(db_host,db_user,db_pwd);
if(!($conn)) echo "Failed To Connect To The Database!";
else{
if(mysql_select_db(db_name,$conn)){
try{
$qry = "SELECT Name,Link FROM downloads WHERE ID=$id";
$result = mysql_query($qry);
//Check whether there's a result with the id number
if(mysql_num_rows($result)==1){
while($rows = mysql_fetch_array($result)){
//If there's one take the details into variables
$nam = $rows['Name'];
$link = $rows['Link'];
}
//Updating the counter by 1
$qry = "UPDATE downloads SET Counter = Counter+1";
mysql_query($qry);
}else{ $error = true; }
}catch(Exception $e){
//If an Exception occurrs make $error true
$error = true;
}
// At last check whether $error is true, if so immediatly redirect to the home page so that an attacker cannot take use of any error
if($error) header("Location: index.php");
}
} |
d'avance merci !