Return to Snippet

Revision: 44267
at April 8, 2011 21:30 by JonnySnip3r

Initial Code
// Connect to the server::
	or die('Sorry, an error occurred when connecting to the server.');

// Select the database::
	or die ('Sorry, an error occurred when select the database.');
	if(isset($_POST['post']) && !empty($_POST['post_title']) && !empty($_POST['post_body']))
		// Set up and clean our variables
		$title = strip_tags(mysql_real_escape_string($_POST['post_title']));
		$body = strip_tags(mysql_real_escape_string($_POST['post_body']));
		$sql = "INSERT INTO posts VALUES (NULL,'$title','$body')";
			echo 'Thanks! you have made a post!';
			echo 'Damn! it failed to post.' . mysql_error();

		<title>Carl's Forum</title>

		$sql = "SELECT * FROM posts ORDER BY post_id DESC";
		$query = mysql_query($sql);
		while($row = mysql_fetch_array($query)) :
		<h1><?php echo $row['post_title']; ?></h1>
		<p><?php echo $row['post_body']; ?></p>
		<?php endwhile; ?>
		<form method='post' action='#'>
			<input type='text' name='post_title' /><br />
			<textarea name='post_body' rows='10' cols='50'></textarea><br />
			<input type='submit' name='post' value='Post' />

Initial URL

Initial Description
Just a simple php insert script.

Initial Title
Simple Database Insert

Initial Tags
database, sql, php, simple

Initial Language