I am newbie as far as PHP is concerned. But I am thrilled. Could anyone tell me what's wrong with this code? Sometimes it shows errors.
<?php
if (isset($_GET['id'])) {
$id = $_GET['id'];
$curPageName = $curPageName. '-' .$id;
}
$sql = "SELECT counts FROM visitor_counter WHERE page_name = '$curPageName'";
$result = mysqli_query($conn, $sql);
$page_count = 0;
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$page_count = $page_count + 1;
$visits = $row["counts"] + 1;
}
}
if ($page_count < 1) {
$sql = "INSERT INTO visitor_counter (page_name, counts) VALUES ('" .$curPageName. "', '1')";
if ($conn->query($sql) === TRUE) {
$visits = "1";
} else {
echo "";
}
}else{
$sql = "UPDATE visitor_counter SET counts = '$visits' WHERE page_name = '$curPageName'";
$result = mysqli_query($conn, $sql);
}
echo $visits. " hits";
?>