Jump to content

My Message Board is ending miserably


Lamez

Recommended Posts

Alright, I am making a message board, and I cannot get it to work properly

 

I want the viewboard to look like this

(those will be links)

 

A Title

Another Title

One More Title

 

then you can click on the links, or titles and it redirects you to the page with the message, and other info like user and so on..

 

Well I am getting errors all over the place this is what I have:

 

on post.php: (already connected to the DB, I took it out the code.)

<html>
<head>
<title>Post a Topic</title>
</head>
<body>
<?php
if (!isset($_POST['submit'])) {
?>
<form action="" method="post">
  :title: 
    <label> 
    <input name="title" type="text" id="title" maxlength="50">
  </label>
    <br>
    message: <textarea name="message" cols="50" rows="15" id="message"></textarea>
  
  <br>
<input type="submit" name="submit" value="Submit!">
</form>
<?php
} else {
$title = $_POST['title'];
$username = $session->username;
$comment = $_POST['message'];
mysql_query("INSERT INTO `comment` (title, username, message) VALUES ('$title','$username', '$message')");

echo "Your Comment has been added.<br>";
print '<a href="view.php">View Message Here</a>';

}

?>
</body>
</html>

 

view.php: (this is the page I am having trouble with)

$query  = "SELECT title, username, message FROM board";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$getlink = $_GET["topic"];
if ($getlink == "{$row['title']}") {
echo "Username :{$row['username']} <br>" .
         "Subject : {$row['title']} <br>" .
         "Message : {$row['message']} <br><br>";
}
else {
echo "<a href=\"?topic={$row['title']}\">{$row['title']}</a><br>";
}

} 

The ouput is it shows all the messages on one page, not divided up like I wanted (?topic=<TOPIC TITLE>)

 

I am not sure what I am doing wrong, any help?

Link to comment
Share on other sites

Don't you think it would help if you post up the error messages so it would be easier for us to help you? That is if you want a fast answer. A lot of people neglect to find the errors for you. Thankfully it's not a particularly long code. But just to let you know. :)

 

$title = $_POST['title'];
$username = $session->username;
$comment = $_POST['message'];
mysql_query("INSERT INTO `comment` (title, username, message) VALUES ('$title','$username', '$message')");

Variable $message is undefined.

Link to comment
Share on other sites

ya I fixed that after I posted, the variable.

 

I fixed all the errors, I just missed some ; and some "

 

but the out come it not what I want it

 

when you view the board it would look like this

 

Subject one

another topic

a new title

 

or whatever they name it, and it will link to the post, but it does not link it right

 

I want the link to look like

 

?topic=subject one

 

or whatever they name it, then in the topic, it shows the message, and username

 

that is working either.

 

any help?

 

Sorry guys

Link to comment
Share on other sites

You can use str_replace to replace the spaces with underscore.

 

$title = str_replace(" ", "_", $title);

 

Then when getting the title from the URL, you have to replace all underscores with spaces.

 

$title = str_replace("_", " ", $_GET['title']);

 

Something like that?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.