Getting form to post results on same page

I am working on this page here: http://www.thebrightfield.com/vicinity/post.html

What I would like to happen when you enter text in “What’s Happening” is for it to post the results below the form on the same page.

Here is what I have for post.php: http://pastebin.com/G5vmb5vi

Here is what I have for post.html: http://pastebin.com/Cgua71uE

When you put user input inside a MySQL query you must escape it:

[php]$sql=“INSERT INTO Posts (happening) VALUES (’” . mysql_real_escape_string($_POST[‘happening’]) . “’)”;[/php]

You also post the same select_db command twice:

[php]mysql_select_db(“choward_vicinity”, $con);[/php]

To actually put your new content on the page, you would use file_put_contents. As you’re echoing out this data, you can use output buffering to get PHP to temporarily hold onto everything you output, then you can use this data again:

[php]ob_start();

// All Data for page

$contents = ob_get_contents(); // Get everything collected
ob_end_flush(); // Output everything we’ve buffered

ob_put_contents(‘post.html’, $contents);[/php]

Output Buffering Control (PHP Manual)

Sponsor our Newsletter | Privacy Policy | Terms of Service