Devo creare un contatore per la sezione membri (contare il numero di volte che un utente ha effettuato il login).Il contatore non incrementa in PHP/MySQL
Ho il seguente script (counter.php):
<?php
$conn = mysql_connect("localhost", "myuser", "mypass");
mysql_select_db("test");
$sql = "SELECT views FROM members WHERE mid = " . $_GET['mid'];
$result = mysql_query($sql);
if (!$result)
{
mail(ADMIN, 'Cannot Get: ' . mysql_error(), mysql_error());
}
while ($row = mysql_fetch_assoc($result))
{
$count = $row['views']++;
}
$query = "UPDATE members SET views = '$count' WHERE mid = " . $_GET['mid'];
mysql_query($query);
mysql_close($conn);
// show the logo using header() and readfile(); // that part work
?>
DB:
CREATE TABLE `members` (
`mid` int(11) NOT NULL AUTO_INCREMENT,
`views` int(11) DEFAULT '0',
/* etc...*/
PRIMARY KEY (`mid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Ora, quello che faccio nel mio file .htaccess è:
RewriteEngine On
RewriteRule ^img/logo([0-9]+).jpg$ /counter.php?mid=$1 [L]
ma per qualche ragione il mio contatore non conta correttamente. Cosa mi manca?
Assicurati di sapere tutto sull'iniezione SQL e sul filtro di input. – grossvogel
Infatti. Non provare a inserire id 'mid = 1; elimina% 20da% 20members; -' nella url. :) – GolezTrol
Ho pensato che il '([0-9] +)' lo impedirà, non è così? – Tech4Wilco