prepare("select * from $userstable where LinkId = :linkid"); $query->bindValue(":linkid", $linkid); $query->execute(); try { $row = $query->fetch(PDO::FETCH_ASSOC); if (!$row) { die("Link not found"); } else { $db->exec("update $userstable set hits=hits+1 where LinkId = $linkid"); $url = $row["url"]; } } catch(PDOException $ex) { die("Error connecting to database"); } header("Location: $url", true, 302); ?>