View Full Version : What script will do this?

10-04-2004, 02:40 AM
Ok guys well basically I'm looking for a very basic php script... its like a guestbook but it won't be used for that.

I want to get a script that basically .... allows me to have people post without really requiring anything else than the post itself.

All thats gotta happen is the post will be made and the page where all the posts are made will have the posts numbered, first post being #1... and I want to show nothing else besides the post itself with post number.

I do want to log IP, and time for personal records and incase banning is needed. Thank you.

For All i care .. all the script wil have is a page where you go make the post...
another where the posts are saved... and a last page where they are displayed as follows:

3 Thrid Post
2 Second post
1 First post

After that I will just work everything to look like I want with css, thanks.

10-04-2004, 03:45 AM
<table width="95%" align="center" class="content2">
include ("db_connect.php");
$sql = "SELECT * FROM table ORDER BY id DESC LIMIT 10";
$sql = pg_query($sql);
$x = 0;
while($row = pg_fetch_array($sql,NULL,PGSQL_ASSOC))
$class = ($x % 2) ? ("class1") : ("class2");
print "<tr><td class=\"$class\"> ". $row{"id"] . "</td> <td class=\"$class\">". $row["comment"] ."</td></tr>\n";
<form method="post" action="post.php">
<table width="95%" align="center" class="content2">
<tr><td class="content2">Name:</td> <td class="content2">&nbsp;<input type="text" name="name"></td></tr>
<tr><td class="content1">Comment:</td> <td class="content1">&nbsp;<input type="text" name="comment" maxlength="100"></td></tr>
<tr><td class="content2">Website:</td> <td class="content2">&nbsp;<input type="text" name="website"></td></tr>
<tr><th class="content1" colspan="2"> <input type="hidden" value="tag" name="page"><input type="submit" value="Tag It!"> <input type="reset" value="Clear It!"></th></tr>

And post.php would be like:

if ($HTTP_POST_VARS["comment"] != "")
$comment = nl2br(htmlentities($HTTP_POST_VARS["comment"], ENT_QUOTES));
$sql = "INSERT INTO table VALUES (DEFAULT, '$comment', '$ip')";
$sql = pg_query($sql);

That is, of course, if you are running PostGreSQL.

Edit: Opening PHP tag got messed up. ;-;

10-04-2004, 04:28 AM
Heh thanks but what is PostGreSQL.. all i run is mysql

10-06-2004, 08:10 AM
I still need help on this =-/.. heh

I need to know the mysql way of doing it and .. err what databse is named etc.. how paths are defined to database..


sir pannels
10-06-2004, 01:17 PM
Hey Data,

That script looks to me like it will work with MySQL the query's are universal in this case... you need to open connection your database however, as in that script the file db_connect.php is being used as connection.


10-06-2004, 11:47 PM
Hi.. what exactly do I need to change and how do I open the connection..

I hve never worked with php and databases.

10-07-2004, 12:05 AM

Read and learn young padawan.

10-07-2004, 12:07 AM
Essentially, throughout the script, replace pg_ with mysql_

As for the database connection, replace

include ("db_connect.php");


$db = mysql_connect('database_location','username','password') or die("Couldn't connect to the database.");
mysql_select_db('database_name', $db) or die("Couldn't select the database");

Just replace the parameters accordingly.

You've of course got to make sure the database/tables are setup correctly, and even still I'm not sure what other issues you might run into...

Good luck,