Here is the catch though, I do select the database at the beginning of the script.
<?php
//To test this out run this query!
/*
CREATE TABLE `db` (
`id` INT NOT NULL ,
`name` TEXT NOT NULL ,
`body` TEXT NOT NULL ,
`date` TEXT NOT NULL
) TYPE = MYISAM;
*/
if( $_POST['name'] != "" && $_POST['body'] != "") {
$name = stripslashes($_POST['name']);
$body = stripslashes($_POST['body']);
$date = date("F j, Y. g:i A");
#-----You need to change these values, or you will want to strangle me :-)-----#
$sql_server = "localhost"; //This is the name of your server, usually it is 'localhost'
$sql_name = "root";
$sql_pass = "";
$sql_db = "guest";
#-----Don't edit below this, or you will want to strangle me again... :-)-----#
mysql_connect($sql_server,$sql_name, $sql_pass);
mysql_select_db($sql_db);
$id = mysql_query( "SELECT `id` FROM `db` ORDER BY `id` DESC" );
$id = mysql_fetch_row( $id );
for( $i=0; $i<count( $id ); $i++ ) {
$total = $id[$i] + 1;
mysql_query( "INSERT INTO db (id, name, body,date) VALUES('$total', '$name', '$body','$date')" );
echo mysql_error();
echo "Your post has been added!";
$_POST['name'] = "";
$_POST['body'] = "";
}
} else {
}
mysql_connect($sql_server,$sql_name, $sql_pass);
mysql_select_db($sql_db);
echo "<table>";
$id = mysql_query(" SELECT `id` FROM `db` ORDER BY `id` DESC" ) or die(mysql_error());
while( $id = mysql_fetch_row( $id ) ) {
echo "<tr>";
echo "<td>";
echo "<strong>$id[name]</strong>";
echo "</td>";
echo "<td>";
echo "$id[date]";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo "</td>";
echo "<td>";
echo "$id[body]";
echo "</td>";
echo "</tr>";
}
echo "</table>";
?>
<form action="<?=$_SERVER['PHP_SELF'] ?>" method='post'>
<table>
<tr>
<td>Name:
</td>
<td><input type='text' name='name' size='25'>
</td>
</tr>
<tr>
<td>Body:
</td>
<td><textarea name='body' rows='15' cols='45'></textarea>
</td>
</tr>
<tr>
<td>
</td>
<td><input type='submit'> <input type='reset'>
</td>
</tr>
</table>
</form>
Sorry that it is a little long..
Any help is greatly appreciated!

New Topic/Question
Reply




MultiQuote



|