Help - Search - Members - Calendar
Full Version: Simple Guestbook/Tagwall
Pixel2Life Forum > Member Tutorials and Requests > Forum Tutorial Archives > PHP Tutorials
Klubba
I just joined, so i don't know the basics of writing a tutorial. So please be nice to me victory.gif

Well, i'm in a hurry so i will make this short and quick. All you need to complete this tutorial is a bit HTML skills to understand the syntax. And a webhotel with PHP and a MySQL database.

It is allways god to start by making a database, so let's do that. Go to phpmyAdmin and put this code into:
CODE
CREATE TABLE `tagwall` (
`id` int(8) NOT NULL auto_increment,
`email` varchar(255) NOT NULL default '',
`name` varchar(255) NOT NULL default '',
`tag` text NOT NULL,
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=0;


Ok, now when we have made our table, then lets start with a form who writes our data into our database (victory.gif).
It is just simple HTML so i won't tell alot about it bigwink.gif
So make a new file call it something like "write-tag.htm" and put this code into it:
CODE
<form method="post" action="put-tag.php">
E-Mail:
<input type="text" name="email">
Name:
<input type="text" name="name">
Tag:
<textarea name="tag" cols="50" rows="50"></textarea>
<input type="submit" name="Submit" value="Tag it!!!">
</form>


Now are we ready to to put our data into our database, so make a new file and name it something like "put-tag.php".
Now listen...
What we are going to put all our data into our database. We will build a connection variable and use it to connect to our database. and second we will use the mysql_query command wich writes our data into our database. So put this code into your put-tag.php file:
CODE
<?php
$connection = mysql_connect("localhost","username","password");
mysql_select_db("database", $connection);

mysql_query("INSERT INTO tagwall (email, name, tag) VALUES ('$_POST[email]', '$_POST[name]', '$_POST[tag]')");
mysql_close;
echo "We got your tag!!";
?>


Now we are allmost done, we just need to print all the data, so let's move on to the last file...
Make a new file and name it tagwall.php or something like that. And put this code into:
CODE
<?php
$connection = mysql_connect("localhost","username","password");
mysql_select_db("database", $connection);

$query = mysql_query("SELECT * FROM tagwall ORDER BY id DESC LIMIT 100") or die(mysql_error());
while ($row = mysql_fetch_assoc($query)) {
?>
<table>
<tr>
<td>From: <a href="mailto:<?=$row[email]?>"><?=$row[name]?></a></td>
</tr>
<tr>
<td><?=$row[tag]?></td>
</tr>
</table>
<?php
}
?>


Well, i did not test this script so i don't know if it works, but try it and ask if you have any problems or just leave a comment if you like w00t.gif

Bye... hiya.gif
maddog4696
Nice, tutorial, but one thing I found to be wrong I think is,
mysql_close;

which should be mysql_close($connection);
I think,
mysql_close; is just setting there and doesn't know what conenction to close.


Also this is incorrect.
<textarea name="nyhed" cols="50" rows="50"></textarea>
name should be tag not nyhed.

<textarea name="tag" cols="50" rows="50"></textarea>
Klubba
Oh yeah. I was making a news system out of it to a m8 of mine before i maked this tut. So some of the HTML was just copy'ed.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.