-1
if (isset($_POST['clear'])){
    $sql = mysql_query("DELETE FROM hitcounter","ALTER TABLE hitcounter AUTO_INCREMENT=0") or die (mysql_error());
}

I am trying to make a hitcounter that counts the amount of hits on a page. I have everything done except the clear button. I need the hit count to go back to 0 but i can't get it to work

Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
PREZI
  • 3
  • 2
  • You can't execute those two queries like that using `mysql_query()`. However, you can use [`mysqli_multi_query()`](http://php.net/manual/en/mysqli.multi-query.php) to execute multiple queries which are concatenated by a semicolon. Or you can even use `PDO`, see [this answer](http://stackoverflow.com/a/6461110/5517143). – Rajdeep Paul Apr 23 '16 at 18:52
  • A bit off-topic... It seems odd to me that resetting auto_increment is involved at all. Plus, you'd probably want to reset it to `1`, not `0`. – Bitwise Creative Apr 23 '16 at 19:07

1 Answers1

0

You can use CLIENT_MULTI_STATEMENTS in mysql_connect's 5th argument. For more information, refer this link:https://mnshankar.wordpress.com/2009/08/08/mysql-stored-procedure-invocation-from-php/

Aparna
  • 255
  • 1
  • 8