Web designing newb. Creating a PHP forum from scratch!

I tried that before but in the wrong place :o

I think I'm going to save the messing around on how it looks and work on some advance features.

> Administrative Functionality
> Users are table edit their own posts
> Users are able to quote other messages in their posts.
> Users are able to add an avatar to their messages.

I'm going to struggle on these. I have a very vague idea on how to tackle administrative and quoting messages. Any advice?
 
As far as quoting messages goes, how about adding this functionality into the 'reply' form?

Ie. say you have the file reply.php which is used to add a reply to a thread.

I assume the thread id must be sent to the file via GET, ie.
Code:
reply.php?threadid=xxxxxxxx

How about putting a piece of php code in the reply.php file that looks for a 'quote' variable in the querystring containing the thread id to quote from, and the post to quote. If these exist, the script retrieves the post and puts it into the reply box surrounded by [QUOTE ] tags.

Code:
if(isset($_GET['threadid']) && isset($_GET['quote_post'])) {
$qthread = $_GET['threadid'];
$qpost = $_GET['quote_post'];

// code to retrieve this post from the database

$qdata = mysql_result($result, null);
}

And then inside the reply textarea:

Code:
<textarea><?php if(!empty($qdata)) echo $qdata; ?></textarea>

Then at the bottom of each post, have "Quote Post" button which calls "reply.php?threadid=XXXXXXXX&quote_post=XXX".

The next step is, when you display a thread, to parse each post for [QUOTE ] tags before it's displayed. If they're found, surround the quote with a border or something.

I don't know exactly how you've laid out the forum, but this is how I'd go about doing that.

Jon
 
&nbsp; should add a space between the password box and the login box.

Code:
<td><input class="smallfont" size="10%" name="mypassword" type="password" id="mypassword">
&nbsp;<input class="button" type="submit" name="Submit" value="Login"></td>
Or add another column to the table that holds the login info.

You'd be better using a left-margin on the login button in CSS than a non-breaking space in the code as this is presentational not structural.

Also, the login panel should not be part of a table, as it's not tabular data. Stick it in a div and then position it using the margin / float properties in CSS.
 
Here's my css for the main page in action :cool:

80546491gu3.jpg


So chuffed with it :D
 
i guess adding the option for an avatar would be quite simple

just have an extra field in the user table in your database that holds the url to any picture they choose. Users can then change this or remove it as they please
 
Just another thought, you could always base64encode the user's avatar and store it in the database along with the rest of their details.

Jon
 
What's wrong with me? :(

I should be revising for my exam, but I'm actually enjoying this :confused:

I'v got 2 issues:
1) Where the username will go I have create a table and when I alter the position of left in CSS either 15/16%, it's goes a couple of pixels either side​
2) I have outlined the 2 white boxes, that I intend to add. Surely there must be a way to group all 3 tables and make one container per post, so that it doesn't all go balls up?​

poststructurerq3.jpg


Code:
table.t4
{
position: absolute;
border: 1px solid #f39707;
width: 15%;
height: 25%;
left: 15%;
}

Thanks once again.
 
they are horrible horrible things. you will just have to keep tweaking it. Personally I use pixels not percentages but that is not the best way
 
If you're not already using it, download Firefox and the web developer toolbar.

There's an option to outline table cells so you can see what's going on.

NEVER put tables inside tables, you'll just end up with a messy code soup.

you can do all you need using <tr>, <th>, <td> and the colspan / rowspan attributes.

Saying forum posts are tabular data is a bit of a stretch tbh, i'd probably avoid tables all together.

*edit* The thread list IS tabular though so tables for that is fine - i'm talking about actually inside the thread when reading each post.
 
Last edited:
You have to think of it like a grid - if you tell a cell to span 2 rows you need to make sure you leave a gap in the next row for it to fit into.

The same goes for colspan, all rows need the same number of columns or its not a valid table. You might get away with it looking ok in a browser but its not good practice.

Play around with the following until you're comfortable with how the table grid works.

Code:
<html>
<head>
    <style>
        table {
            border-collapse: collapse;
        }
        
        td, th {
            border: 1px solid;
            padding: 2px 5px;
        }
    </style>
</head>
<body>
<h1>Table Demo</h1>
<table>
    <tr>
        <th>header cell 1</th>
        <th colspan="4">header cell, spanning 4 columns</th>
    </tr>
    <tr>
        <td>Cell 1</td>
        <td>Cell 2</td>
        <td>Cell 3</td>
        <td>Cell 4</td>
        <td>Cell 5</td>
    </tr>
    <tr>
        <td colspan="4">cell spanning 4 columns</td>
        <td rowspan="2">cell spanning 2 rows</td>
    </tr>
    <tr>
        <td>Cell 1</td>
        <td>Cell 2</td>
        <td>Cell 3</td>
        <td>Cell 4</td>
    </tr>
    <tr>
        <td>Cell 1</td>
        <td>Cell 2</td>
        <td>Cell 3</td>
        <td>Cell 4</td>
        <td>Cell 5</td>
    </tr>
</table>
</body>
</html>
 
delete1cs4.jpg


Right guys, I'm having a problem with deleting users. Basically, I have an ID which you select and when I press delete, the page refreshes but no member is deleted from the database.

Below is the php for the button, checkbox and the delete command:

Code:
<input class="button" name="delete" type="submit" id="delete" value="delete">
---------------------------------------------------------------------------
<td align="center" bgcolor="#000000"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
---------------------------------------------------------------------------

<?
// Check if delete button active, start this
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
}

// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=deleteuser.php\">";
}
}
mysql_close();
?>
I'd appreciate any advice as per usual :(
 
You'll need to use a form (can't see it in what you pasted above).

Code:
<form id="form" name="form" method="get" action="">
---------------------------------------------------------------------------
<input class="button" name="delete" type="submit" id="delete" value="delete">
---------------------------------------------------------------------------
<td align="center" bgcolor="#000000"><input name="userid" type="userid" id="userid" value="<? echo $rows[ "id" ]; ?>"></td>
---------------------------------------------------------------------------
</form>

<?php
//--------------------------------------
// Form has been submitted, let's see what it's said...
//--------------------------------------
if( isset( $_GET[ "form" ] ) )
{
	//--------------------------------------
	// UserID from the form
	//--------------------------------------
	$UserID = $_GET[ "userid" ];
	
	//--------------------------------------
	// Prepare zee SQL!
	//--------------------------------------
	$sql = "DELETE FROM $tbl_name WHERE id='" . $UserID . "'";
	
	//--------------------------------------
	// Send it off
	//--------------------------------------
	$result = mysql_query( $sql );
	
	//--------------------------------------
	// Let's see now...
	//--------------------------------------
	if( $result ) {
		echo "<meta http-equiv=\"refresh\" content=\"0;URL=deleteuser.php\">";
	} else {
		echo "Something messed up...";
	}

	//--------------------------------------
	// Close it up.
	//--------------------------------------
	mysql_close( );
}
?>

Hope I understood correctly and is what you need (and somewhat works :p).
 
Last edited:
You'll need to use a form (can't see it in what you pasted above).

Code:
<form id="form" name="form" method="get" action="">
---------------------------------------------------------------------------
<input class="button" name="delete" type="submit" id="delete" value="delete">
---------------------------------------------------------------------------
<td align="center" bgcolor="#000000"><input name="userid" type="userid" id="userid" value="<? echo $rows[ "id" ]; ?>"></td>
---------------------------------------------------------------------------
</form>

<?php
//--------------------------------------
// Form has been submitted, let's see what it's said...
//--------------------------------------
if( isset( $_GET[ "form" ] ) )
{
	//--------------------------------------
	// UserID from the form
	//--------------------------------------
	$UserID = $_GET[ "userid" ];
	
	//--------------------------------------
	// Prepare zee SQL!
	//--------------------------------------
	$sql = "DELETE FROM $tbl_name WHERE id='" . $UserID . "'";
	
	//--------------------------------------
	// Send it off
	//--------------------------------------
	$result = mysql_query( $sql );
	
	//--------------------------------------
	// Let's see now...
	//--------------------------------------
	if( $result ) {
		echo "<meta http-equiv=\"refresh\" content=\"0;URL=deleteuser.php\">";
	} else {
		echo "Something messed up...";
	}

	//--------------------------------------
	// Close it up.
	//--------------------------------------
	mysql_close( );
}
?>

Hope I understood correctly and is what you need (and somewhat works :p).

holy over-commenting batman
 
Would it not be better to use array_walk with that delete users page?

Example :

Code:
function delete($userid) {

// do sql stuff

mysql_query("DELETE FROM users WHERE userid='$userid'");

//redirect

}

array_walk($_POST['selected_user'], 'delete');

And for the checkbox :
Code:
<input type="checkbox" name="selected_user[]" value="<?=$data['userid'];?>">
 
Last edited:
Obligatory "sanitise your user input" post.

Also, why use so many comments, Xtrm2Matt? It just makes the code look more complicated than it really is – that snippet shouldn't need any comments at all (especially with decoration).
 
Back
Top Bottom