Web designing newb. Creating a PHP forum from scratch!

Soldato
Joined
14 Apr 2004
Posts
11,869
Location
UK
Hey guys,

I'm creating this thread as something that I can refer back to and get help in terms of validation and advice in general.

A little big about my web experience, I have next to none and have created rubbish sites in the past, it's what I do best :D

I have however, always wanted to get into it, but I've just never got round to doing so. However, now I'm forced to do it for a Uni assignment which is due in a month. I must create a full PHP forum from scratch with features such as using sessions, registering users, threads with a few options and some extra 'functions' like displaying avatars.

As always, I like to try and get stuff done by myself, however this is one that I feel I will struggle with.

Today I've started reading many tutorials on HTML & CSS, using places such as W3Schools and HTMLDog.

Here is a quick mock-up I designed in ps:

forumwf4.jpg


I've found Uni lectures to be pretty dire, so I'll be reading up on books and websites. My lecturer said that is fine as long as I reference them. I'm not going to rip any code or view other peoples sources.

I would like some advice on the process of my development and any common things to avoid in general. Just some general advice.

I plan on implementing a simple and clean design, using CSS and then start with the PHP side of things and then bringing the two together!

I'd appreciate any advice and I will regularly post my progress as I make some.

Thank you for your time :)
 
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
Thanks for the the input guys.

Sirius, thanks for the advice! I've started on the php and MySQL section of things. Moving very slow atm the moment, getting used to it! I'll leave the bells and whistles for when I'm near completion.

Are you allowed to use an existing PHP framework to work from? It could cut down a lot of your development time.
Unfortunately we can't, I asked if I was allowed to look something like Vanilla open source forum and understand how it's put together. I was given a big no :(

I'm moving a lot slower than I expected!
 
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
There is nothing wrong with you looking at open source software and see how it is done. As long as you don't blatantly rip them off.

Have you done ANY PHP/XHTML/CSS for this particular module/course? It would appear not, if so it seems strange you are expected to tackle a very complex assignment with zero experience and NOT able to look at other people's work.
My sentiments with the your first statement!

I'm in my second year of Software Engineering and they love raping us with new material. We started this module in October and all we learnt was to echo, insert a table, images and a few other bits and bobs and now they expect us to create a fully functional forum :confused:

They've given us a booklet, but the notes are dire.

Have you got MSN Sirius? Just want to run an idea past you if you don't mind.
 
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
Thanks Dj_Jestar, I've screwed my head on and that's definitely the way forward. I shall be spending most of the weekend on php.net and other good sites reading up!
 
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
Here you go Sic:

Code:
Basic task
The forum must include the following functionality:
> Messages are displayed in a single long list.
> Messages are identified by a title, username and time and date when they were created by the user.
> You must provide a form through which users can register to join the site.
> Only registered users can create messages.
> You must provide a form on which registered users can create messages.
> Unregistered visitors can view the message list.
Your code must be neatly formatted with proper indentation, meaningful variable, class and method. Your code must successfully validate as XHTML transitional using the W3C validator.
60 Marks Max

Advanced task
Once you successfully complete the basic task you may add extra functionality from this list:
> Users are able to add an avatar to their messages.
> Messages are grouped into topics with a list of topics displayed and all messages relating
to the topic shown in posting order.
> Users are able to edit their own messages after posting them.
> Users are able to quote other messages in their own.
> Messages are threaded within topics.
> Administrative functionality is provided which lets an identified administrator delete or edit posts.
40 Marks Max
 
Last edited:
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
An update, I started making great progress but due to personal problems, I've had to put a lot of work on hold. I've managed to spare a few hours to work on the forum and I'm experiencing problems.

So far I've created the layout and I've tried linking my form to the database and I get the following error:

Warning: mysql_connect(): Access denied for user 'nobody'@'localhost' (using password: NO) in 'dir/xyz' on line 9 cannot connect

I have the following opening code:

Code:
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="my_db1"; // Database name
$tbl_name="create_thread"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db(my_db1")or die("cannot select DB");

Basic layout using html:

sofarwn2.jpg
 
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
I need some urgent help please!

mainforumrp3.jpg


I've created the main forum and the form as above. I've used tables to make both of them and a few friends have opposed against them and they've highly recommend I start off with divs. I've been playing around for about an hour and i'm not making much progress. I've read up on the all the usual sites but I'm not making much progress. Any advice on achieving the layout above using divs instead of tables?
I've used a tutorial to create this for example purposes.
 
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
Am I correct in assuming tables and CSS don't work very well together?

If you have a month to do this and nothing else (i.e. work and other assignments) you should have it done in no time.
Unfortunately that is the problem. I've been working 2 jobs and as one of them I've been running a family business in absence of my brother. In addition I have 2 other assignment and a further 2 exams. I've also had family over. So I'm really struggling to cope atm but I'm trying to do what I can. Hopefully I should get a large amount done over the next 7 days as I've planned my time wisely!
 
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
Hey guys, making a reasonable progress! I've gotten this far:

(Click for larger)


My reply part is a bit fubarred but I should have it resolved by tonight!

I'll appreciate any feedback/criticism! :)
 
Last edited:
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
Hahaha, owned :D

Just thought the dons would have a nosey and tell me off for having one that leads to competitors etc

Thanks for the feedback, mucho appreciated :)

My code is properly indented with meaningful comments and variables. Here's a snippet:

Code:
// get value of id that sent from address bar
$id=$_GET['id'];

$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" bgcolor="#FFFFFF">
<tr>

You can also see some in the screenshot :)

I'll be needing some advice regarding registering users and transforming this baby into a proper forum!
 
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
I'm really struggling with an error I can't figure out.

I've added an if statement that does a sequence of commands else it echo's ERROR which it does and I can't seem to figure out what's going wrong.

PHP:
// Insert reply
$sql2="INSERT INTO $tbl_name(reply_id, a_id, a_name, a_reply, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_reply', '$datetime')";
$result2=mysql_query($sql2);

if($result2){
echo "Successful<BR>";
echo "<a href='view_thread.php?id=".$id."'>View your reply</a>";

// If added new reply, add value +1 in reply column
$tbl_name2="create_thread";
$sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'";
$result3=mysql_query($sql3);

}
else {
echo "ERROR";
}

mysql_close();
?>


It's absolutely doing my nut in, as I've spent hours on it :(
 
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
Thank you for the response, when I replaced your code I got the following:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''create_reply' ('reply_id', 'a_id', 'a_name', 'a_reply', 'a_date

With my code and the error reporting, I got the following:

ERROR: The SQL Server said:
Duplicate entry '1' for key 1
:confused:
 
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
I get the following:
ERROR: The SQL Server said:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''reply_id', 'a_id', 'a_name', 'a_reply', 'a_datetime') VALUES ('

Rob, any reason in particular? Or is it just good practice?
 
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
The error you're seeing is because you have quotes around the column names.

Change
Code:
('reply_id', 'a_id', 'a_name', 'a_reply', 'a_datetime')

to
Code:
(reply_id, a_id, a_name, a_reply, a_datetime)
It's the values that I have quotes around:

Code:
$sql2="INSERT INTO $tbl_name(reply_id, a_id, a_name, a_reply, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_reply', '$datetime')";
$result2=mysql_query($sql2);
 
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
I pretty darn certain the problem is minor, but I can't get my head around it! I've spent a few hours on it trying different kinds of code but alas not getting very far.
 
Last edited:
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
put back ticks around the table like so....

Code:
$result2 = mysql_query("INSERT INTO `$tbl_name` (reply_id, a_id, a_name, a_reply, a_datetime) VALUES('$id', '$Max_id', '$a_name', '$a_reply', '$datetime')");
I just tried that and I got "Parse error: parse error in xyzdir/etc/etc.php"

I don't understand this error: "Duplicate entry '1' for key 1" :(
 
Soldato
OP
Joined
14 Apr 2004
Posts
11,869
Location
UK
I'll look into that when I'm closer to completion. I did a lot of reading last night and because I was computer-less at work, I used the ancient means of using a pen and paper! :eek:

I've pretty much figured out how I will register users and then allow them to log in. I also read a chapter on cookies/session and I think I'll be using sessions. I've got a vague idea of how I will encrypt passwords and incorporate a link for "forgotten password".

Whilst reading a dummies guide to php & mysql, one of the code examples included ob_start. Now after googling around it's an output buffer but I have no idea what it's used for. Could anyone please elaborate on what it is and what it's used for? Cheers :)
 
Back
Top Bottom