oz11 Posted July 14, 2023 Share Posted July 14, 2023 Well.. basically just wrote this. But want it to be forwarded to a page if it's complete... However, it only loads the final conditional if the page is refreshed a second time.. Help, please.Code: <?php include 'config.php'; $user_ip=$_SERVER['REMOTE_ADDR']; $news_ref = $_GET['ref']; $stmt = $pdo->prepare("SELECT count(*) FROM outgoing_count WHERE IP = ? AND news_reff = ?"); $stmt->execute([$user_ip, $news_ref ]); $count = $stmt->fetchColumn(); if($count == 0){ $sql = "INSERT INTO outgoing_count (IP, news_reff) VALUES (?,?)"; $stmt= $pdo->prepare($sql); $stmt->execute([$user_ip, $news_ref ]); } else { $stmt = $pdo->prepare("SELECT count(*) FROM news WHERE reference=?"); $stmt->execute([$_GET['ref']]); $check_exist = $stmt->fetchColumn(); if($check_exist == 0){ echo "404 Error: not found"; } else { echo "Redirect. This page has been viewed ".$count."times"; // <--- ONLY SHOWS ON SECOND REFRESH..??... //header('Location: http://google.com'); } } ?> Quote Link to comment Share on other sites More sharing options...
oz11 Posted July 14, 2023 Author Share Posted July 14, 2023 (edited) Updated the code a bit... still doesn't work.. <?php include 'config.php'; $stmt = $pdo->prepare("SELECT count(*) FROM news WHERE reference=?"); $stmt->execute([$_GET['ref']]); $check_exist = $stmt->fetchColumn(); if($check_exist == 0){ echo "error not found"; exit(); } $user_ip=$_SERVER['REMOTE_ADDR']; $stmt = $pdo->prepare("SELECT count(*) FROM outgoing_count WHERE IP = ? AND news_reff = ?"); $stmt->execute([$user_ip, $_GET['ref']]); $count = $stmt->fetchColumn(); if($count == 0){ $sql = "INSERT INTO outgoing_count (IP, news_reff) VALUES (?,?)"; $stmt= $pdo->prepare($sql); $stmt->execute([$user_ip, $_GET['ref']]); } else { echo "Redirect. This page has been viewed ".$count."times"; //header('Location: http://google.com'); } ?> Edited July 14, 2023 by oz11 Quote Link to comment Share on other sites More sharing options...
Solution oz11 Posted July 14, 2023 Author Solution Share Posted July 14, 2023 Fixed code: <?php include 'config.php'; $stmt = $pdo->prepare("SELECT count(*) FROM news WHERE reference=?"); $stmt->execute([$_GET['ref']]); $check_exist = $stmt->fetchColumn(); if($check_exist == 0){ echo "error not found"; exit(); } $user_ip=$_SERVER['REMOTE_ADDR']; $stmt = $pdo->prepare("SELECT count(*) FROM outgoing_count WHERE IP = ? AND news_reff = ?"); $stmt->execute([$user_ip, $_GET['ref']]); $count = $stmt->fetchColumn(); if($count == 0){ $sql = "INSERT INTO outgoing_count (IP, news_reff) VALUES (?,?)"; $stmt= $pdo->prepare($sql); $stmt->execute([$user_ip, $_GET['ref']]); $stmt = $pdo->prepare("SELECT count(*) FROM outgoing_count WHERE news_reff = ?"); $stmt->execute([ $_GET['ref']]); $count2 = $stmt->fetchColumn(); echo "Redirect. This page has been viewed ".$count2."times"; } else { $stmt = $pdo->prepare("SELECT count(*) FROM outgoing_count WHERE news_reff = ?"); $stmt->execute([$_GET['ref']]); $count3 = $stmt->fetchColumn(); echo "Redirect. This page has been viewed ".$count3."times"; //header('Location: http://google.com'); } ?> .. just needed time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.