Devoliping a forum

Hello. I am trying to develop a forum in php but I am facing some problems. If someone can help me please message me to send the files and check it. By the way I am going through this tutorial:

by the way

Please add the link to the tutorial and which error messages you are getting (with the relevant code)

Here is the tutorial:

In the code below categories must show up but this error appears:The categories could not be displayed, please try again later. When I remove this line:WHERE cat_id = " . mysql_real_escape_string($_GET[‘id’]);, categories appears but(see the second code below this code.)

P.S the id inside the $_GET[‘id’] is the <a href=category.php?id at the bottom of the code below

[php]<?php
//create_cat.php
include ‘connect.php’;
include ‘header.php’;

$sql = "SELECT
cat_id,
cat_name,
cat_description
FROM
categories
WHERE
cat_id = " . mysql_real_escape_string($_GET[‘id’]);
$result = mysql_query($sql);

if(!$result)
{
echo ‘The categories could not be displayed, please try again later.’;
}
else
{
if(mysql_num_rows($result) == 0)
{
echo ‘No categories defined yet.’;
}
else
{
//prepare the table
echo ’





';
    while($row = mysql_fetch_assoc($result))
    {               
        echo '<tr>';
            echo '<td class="leftpart">';
                echo '<h3><a href="category.php?id">' . $row['cat_name'] . '</a></h3>' . $row['cat_description'];
            echo '</td>';
            echo '<td class="rightpart">';
                        echo '<a href="topic.php?id=">Topic subject</a> at 10-10';
            echo '</td>';
        echo '</tr>';
    }
}

}

include ‘footer.php’;
?>[/embed]

The code below has to show the topics of the category I choose. The error here is this again: cat_id = " . mysql_real_escape_string($_GET[“id”]); Thhe id is the id is the one at the bottom <a href=topic.php?id=:

[embed=425,349]<?php
//create_cat.php
include ‘connect.php’;
include ‘header.php’;

//first select the category based on $_GET[‘cat_id’]
$sql = "SELECT
cat_id,
cat_name,
cat_description
FROM
categories
WHERE
cat_id = " . mysql_real_escape_string($_GET[“id”]);

$result = mysql_query($sql);

if(!$result)
{
echo ‘The category could not be displayed, please try again later.’ . mysql_error();
}
else
{
if(mysql_num_rows($result) == 0)
{
echo ‘This category does not exist.’;
}
else
{
//display category data
while($row = mysql_fetch_assoc($result))
{
echo ‘

Topics in ′’ . $row[‘cat_name’] . ‘′ category

’;
}
    //do a query for the topics
    $sql = "SELECT  
                topic_id,
                topic_subject,
                topic_date,
                topic_cat
            FROM
                topics
            WHERE
                topic_cat = " . mysql_real_escape_string($_GET['id']);
     
    $result = mysql_query($sql);
     
    if(!$result)
    {
        echo 'The topics could not be displayed, please try again later.';
    }
    else
    {
        if(mysql_num_rows($result) == 0)
        {
            echo 'There are no topics in this category yet.';
        }
        else
        {
            //prepare the table
            echo '<table border="1">
                  <tr>
                    <th>Topic</th>
                    <th>Created at</th>
                  </tr>'; 
                 
            while($row = mysql_fetch_assoc($result))
            {               
                echo '<tr>';
                    echo '<td class="leftpart">';
                        echo '<h3><a href="topic.php?id=' . $row['topic_id'] . '">' . $row['topic_subject'] . '</a><h3>';
                    echo '</td>';
                    echo '<td class="rightpart">';
                        echo date('d-m-Y', strtotime($row['topic_date']));
                    echo '</td>';
                echo '</tr>';
            }
        }
    }
}

}

include ‘footer.php’;
?>[/php]

Category Last topic

Do yourself a favor, throw away that tutorial. I know that tutorial is only four-years old, but mysqli and pretty sure PDO was available at that time. The author of the tutorial should had known better.

Anyways do an internet search (Google search) and search for CMS Forum using Mysqli or CMS Forum using PDO (My Recommendation). —> Or something along that line, but using mysqli or PDO as keywords. Mysql is depreciated and since you want to learn PHP, you might as well learn it right from the start.

Sponsor our Newsletter | Privacy Policy | Terms of Service