Page 1 of 1

Coding Help! (POSTS)!

Posted: Tue Jan 24, 2012 1:11 pm
by Shahlin
I have a text box and a submit button...which posts...the text typed in the text box!
It's A Very Simple Script!

[syntax=php]<?php
if (isset($_POST['post'])) {
$post = $_POST['post'] ;
if ($_POST['submit']) {
if (!empty ($post)) {
echo $post.'<br>' ;

} else {
echo 'Please Type In Something!' ;
}
}
}

?>

<form action="" method="POST">
<input type="text" name="post"> <input type="submit" name="submit" value="Post">
</form>[/syntax]

When I type something and post...it is echoed out and when I type something else and post the previous text goes away!
What I want is...when someone post something, it should be echoed out and when that person post something again! the old post should stay there and the new post should come above it.

Thanks!

Re: Coding Help! (POSTS)!

Posted: Tue Jan 24, 2012 6:01 pm
by jacek
For something this simple you have over complicated it quite a lot. If you are checking to see if the post isset then there is o need to check if the submit button has been pressed :?

So you can make it this

[syntax=php]if (isset($_POST['post'])) {
$post = $_POST['post'] ;
if (!empty ($post)) {
echo $post.'<br>' ;
} else {
echo 'Please Type In Something!' ;
}
}[/syntax]
Then there is no point creating the $post variable since you are just assigning one variable to the other without making any changes to it''s value, so you can make it

[syntax=php]if (isset($_POST['post'])) {
if (!empty ($_POST['post'])) {
echo $_POST['post'].'<br>' ;
} else {
echo 'Please Type In Something!' ;
}
}[/syntax]

then, the easiest way to get what you want would probably be to have the previous messages stored in the session, so every time there is a valid message store it in the session, then have that output at the top of the page.

Re: Coding Help! (POSTS)!

Posted: Wed Jan 25, 2012 10:59 am
by Shahlin
I didn't mean this!

What I meant was....when a user types something it should post above....and he posts something else..it should be posted above the old post! For Example :

User : 2
User : 1
<Text Box> <Submit Button>

Should We Connect It To The DataBase For This?

Re: Coding Help! (POSTS)!

Posted: Wed Jan 25, 2012 12:14 pm
by bowersbros
store it in the database, when you fetch it, use order by id desc to reverse it

Re: Coding Help! (POSTS)!

Posted: Wed Jan 25, 2012 1:11 pm
by Shahlin
Thanks!

Re: Coding Help! (POSTS)!

Posted: Thu Jan 26, 2012 4:39 pm
by Shahlin
bowersbros wrote:store it in the database, when you fetch it, use order by id desc to reverse it


This is my current code! :

[syntax=php]<?php
require 'config.php' ;
if (isset($_POST['post'])) {
$post = $_POST['post'] ;
if (!empty ($post)) {
$query = mysql_query ("SELECT * FROM `post` ORDER BY id Desc LIMIT 30") ;
$row = mysql_fetch_assoc($query) ;
$posts = $row ['post'] ;
if (mysql_num_rows($query)== 0) {
echo 'No Posts Currently!' ;
} else if (mysql_num_rows($query)>=1){
echo $post.'<br>' ;
echo $posts.'<br>' ;
}
$querypost = mysql_query ("INSERT INTO `post` VALUES ('','$post')") ;
} else {
echo 'Please Type In Something!' ;
}
}

?>

<form action="" method="POST">
<input type="text" name="post"> <input type="submit" name="submit" value="Post">
</form>[/syntax]

But It Doesn't Work! Please Help!

Re: Coding Help! (POSTS)!

Posted: Sat Jan 28, 2012 10:47 pm
by jacek
In what way does it not work ?