Jump to content


Photo
- - - - -

Simple Guestbook/Tagwall


  • Please log in to reply
2 replies to this topic

#1 Klubba

Klubba

    Young Padawan

  • Members
  • Pip
  • 24 posts
  • Location:Denmark

Posted 30 June 2005 - 06:58 AM

I just joined, so i don't know the basics of writing a tutorial. So please be nice to me :D

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:
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 (:D).
It is just simple HTML so i won't tell alot about it ;)
So make a new file call it something like "write-tag.htm" and put this code into it:
<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:
<?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:
<?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 :P

Bye... ;)

Edited by Klubba, 07 July 2005 - 04:40 AM.


#2 maddog4696

maddog4696

    Young Padawan

  • Members
  • Pip
  • 4 posts

Posted 05 July 2005 - 12:44 AM

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>

Edited by maddog4696, 05 July 2005 - 12:48 AM.


#3 Klubba

Klubba

    Young Padawan

  • Members
  • Pip
  • 24 posts
  • Location:Denmark

Posted 07 July 2005 - 04:39 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users