<?php //query to find number of stories in database require 'database.php'; $stmt = $mysqli->prepare("select id from news"); if (!$stmt) { printf("Query Prep Failed: %s\n", $mysqli->error); exit; } $stmt->execute(); $result = $stmt->get_result(); while ($row = $result->fetch_assoc()) { $ids[] = $row['id']; } if (!empty($ids)) { for ($i = 0; $i < sizeof($ids); $i++) { showNewsWComments($ids[$i]); } } else { echo "try adding some news in the 'User Page' tab"; } $stmt->close(); ?> <?php function showComments($id) { require 'database.php'; $stmt = $mysqli->prepare("SELECT * FROM comments WHERE news_id=?"); if (!$stmt) { printf("Query Prep Failed: %s\n", $mysqli->error);
$link = $mysqli->real_escape_string($_POST['postLink']); $stmt = $mysqli->prepare("insert into news(title, poster, newsstory, links) values (?,?,?,?)"); if (!$stmt) { printf("Query Prep Failed: %s\n", $mysqli->error); exit; } $stmt->bind_param('ssss', $title, $name, $newstory, $link); $stmt->execute(); $stmt->close(); header("Location: userPage.php"); } } ?> <?php showNewsWComments(); ?> <?php function showProfile() { require 'database.php'; //will show all of user's comments $stmt = $mysqli->prepare("SELECT * FROM users WHERE username=?"); if (!$stmt) { printf("Query Prep Failed: %s\n", $mysqli->error); exit; } $stmt->bind_param('s', $_SESSION['userAccount']); $stmt->execute(); $result = $stmt->get_result();