Lamez Posted January 12, 2008 Share Posted January 12, 2008 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? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 12, 2008 Share Posted January 12, 2008 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. Quote Link to comment Share on other sites More sharing options...
Lamez Posted January 12, 2008 Author Share Posted January 12, 2008 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 Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 12, 2008 Share Posted January 12, 2008 The URL can't have spaces. So you can't type a URL like: http://divinitycoding.net/index.php?id=5&topicname=welcome to divinity coding The part in bold wouldn't work. URLs don't have spaces. Quote Link to comment Share on other sites More sharing options...
Lamez Posted January 12, 2008 Author Share Posted January 12, 2008 oh, well then how do I link to the message? that is the only way I know how to link Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 12, 2008 Share Posted January 12, 2008 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? Quote Link to comment Share on other sites More sharing options...
Lamez Posted January 12, 2008 Author Share Posted January 12, 2008 alright, but then how would I use it with this? {$row['title']} would it be: $title = str_replace("_", " ", {$row['title']}); Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 12, 2008 Share Posted January 12, 2008 $title = str_replace("_", " ", $row['title']); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.