-
Aug 4th, 2014, 06:50 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] php problem
hi,
im having a problem and I cant see the error can anyone help please this is the page http://www.mbdues.co.uk/view_category.php
here is the code there is no error showing.
PHP Code:
<?php
include 'core/init.php';
include 'includes/overall/header.php';
error_reporting(E_ALL);
?>
<h1>View Category Page</h1>
<p>Just a template.</p>
<div id="wrapper">
<?php
// Function that will count how many replies each topic has
function topic_replies($cid, $tid) {
$sql = "SELECT count(*) AS topic_replies FROM posts WHERE category_id='".$cid."' AND topic_id='".$tid."'";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
return $row['topic_replies'] - 1;
}
// Function that will convert a user id into their username
function getusername($uid) {
$sql = "SELECT username FROM users WHERE id='".$user_id."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
return $row['username'];
}
// Function that will convert the datetime string from the database into a user-friendly format
function convertdate($date) {
$date = strtotime($date);
return date("M j, Y g:ia", $date);
}
// Assign local variables
$cid = $_GET['cid'];
// Query that checks to see if the category specified in the $cid variable actually exists in the database
$sql = "SELECT id FROM categories WHERE id='".$cid."' LIMIT 1";
// Execute the SELECT query
$res = mysql_query($sql) or die(mysql_error());
// Check if the category exists
if (mysql_num_rows($res) == 1) {
echo "<a href='create_topic.php'>Click Here To Create A Topic</a><hr>";
// Select the topics that are associated with this category id and order by the topic_reply_date
$sql2 = "SELECT * FROM topics WHERE category_id='".$cid."' ORDER BY topic_reply_date DESC";
// Execute the SELECT query
$res2 = mysql_query($sql2) or die(mysql_error());
// Check to see if there are topics in the category
if (mysql_num_rows($res2) > 0) {
// Appending table data to the $topics variable for output on the page
$topics .= "<table width='100%' style='border-collapse: collapse;'>";
$topics .= "<tr><td colspan='4'><a href='index.php'>Return To Forum Index</a>"<hr /></td></tr>";
$topics .= "<tr style='background-color: #dddddd;'><td>Topic Title</td><td width='65' align='center'>Last User</td><td width='65' align='center'>Replies</td><td width='65' align='center'>Views</td></tr>";
$topic .= "<tr><td colspan='4'><hr /></td><tr>";
// Fetching topic data from the database
while ($row = mysql_fetch_assoc($res2)) {
// Assign local variables from the database data
$tid = $row['id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator = $row['topic_creator'];
// Check to see if the topic has every been replied to
if ($row['topic_last_user'] == "") { $last_user = "N/A"; } else { $last_user = getusername($row['topic_last_user']); }
// Append the actual topic data to the $topics variable
$topics .= "<tr><td><a href='view_topic.php?cid=".$cid."&tid=".$tid."'>".$title."</a><br /><span class='post_info'>Posted by: ".getusername($creator)." on ".convertdate($date)."</span></td><td align='center'>".$last_user."</td><td align='center'>".topic_replies($cid, $tid)."</td><td align='center'>".$views."</td></tr>";
$topics .= "<tr><td colspan='4'><hr /></td></tr>";
}
$topics .= "</table>";
// Displaying the $topics variable on the page
echo $topics;
} else {
// If there are no topics
echo "<a href='index.php'>Return To Forum Index</a><hr />";
echo "<p>There are no topics in this category yet.</p>";
}
} else {
// If the category does not exist
echo "<a href='index.php'>Return To Forum Index</a><hr />";
echo "<p>You are trying to view a category that does not exist yet.";
}
?>
</div>
<?php include 'includes/overall/footer.php'; ?>
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Aug 4th, 2014, 08:50 PM
#2
Re: php problem
something is erroring in the init.php ... I think. Put the error_reporting line before everything else... make it the very first line.
-tg
-
Aug 5th, 2014, 02:45 AM
#3
Thread Starter
Frenzied Member
Re: php problem
I put error_reporting(); at the very top in the init.php file and it isn't throwing any errors?
this is the init.php code
Code:
<?php
session_start();
error_reporting(0);
require 'database/connect.php';
require 'functions/general.php';
require 'functions/users.php';
if(logged_in() === true) {
$session_user_id = $_SESSION['user_id'];
$user_data = user_data($session_user_id, 'user_id', 'username', 'password', 'first_name', 'last_name', 'email');
if (user_active($user_data['username']) === false) {
session_destroy();
header('Location: index.php');
exit();
}
}
$errors = array();
?>
I also did it in the view_catgory.php page and its still saying page cannot be displayed?
I think it maybe coming from my the if statements like this im not sure if im missing any of these {?
Last edited by Jamie_Garland; Aug 5th, 2014 at 02:55 AM.
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Aug 5th, 2014, 06:49 AM
#4
Re: php problem
ungh....
Look at init carefully... in your main file you turned on error reporting... but then in init.php you immediately turned it right back off....
if you want errors to be reported, you need to make sure it's been enabled in all files... if you include a file that's turnign it back off, well, it's been turned off.
Perosnally I only put the error_reporting in the main files, not in includeed files... that way I can turn it on/off page by page rathern than file by file - which can be a pain if you include many files as I have a habit of doing.
-tg
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|