Nov 21, 2009

How to create a guestbook with php !!! - Create your own guestbook.

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Designing > Web Design and HTML

How to create a guestbook with php !!! - Create your own guestbook.

dservice
Before you begein you need to create a database and in this database to create a table called "comentarii". This table should have this fields:
+-----------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+------------------+------+-----+---------+----------------+
| id_comentariu | int(10) unsigned | | PRI | NULL | auto_increment |
| nume_utilizator | text | YES| |NULL | |
| adresa_email | text | YES| | NULL | |
| comentariu | text | YES | | NULL | |
+-----------------+------------------+------+-----+---------+----------------+

Here you have the mysql commands to create table "comentarii":
create table comentarii
(id_comentariu int unsigned default '0' not null auto_increment,
nume_utilizator text,
adresa_email_text,
comentariu text,
primary key(id_comentariu),
unique(id_comentariu),
index(id_comentariu));

This is the code for guestbook.php:
<html>
<head><title>My Guestbook</title></head>
<body>
<p><b>My Guestbook</b></p>
<?
mysql_connect("localhost","user","password");
mysql_select_db("your_database");
$sqlComentarii = "select * from comentari";
$resursaComentarii = mysql_query($sqlComentarii);
while($row2 = mysql_fetch_array($resursaComentarii))
{
print '<div style="width:400px; border:1px solid #ffffff; background-color:#f9f1e7; padding:5px"> <a href="mailto:'.$row2['adresa_email'].'">'.$row2['nume_utilizator'].'</a><br>
'.$row2['comentariu'].'</div>';
}
?>
<br>
<div style="width:400px; border:1px solid #632415; background-color:#f9f1e7; padding:5px;">
<b>Add your comment:</b>
<hr size="1">
<form action="add_post.php" method="POST">
Nume: <input type="text" name="nume_utilizator">
E-mail: <input type="text" name="adresa_email"><br><br>
Comentariu:<br>
<textarea name="comentariu" cols="45"></textarea><br><br>
<center><input type="submit" value="Adauga"></center>
</form>
</div>
</td>
</body>
</html>

This is the code for add_post.php:
<?
if($_POST['nume_utilizator'] == "" || $_POST['adresa_email'] == "" || $_POST['comentariu'] == "")
{
print "Trebuie sa completezi toate campurile!";
exit;
}
mysql_connect("localhost","user","password");
mysql_select_db("your_database");
$nume = strip_tags($_POST['nume_utilizator']);
$mail = strip_tags($_POST['adresa_email']);
$comentariu = strip_tags($_POST['comentariu']);
$sql = "insert into comentarii(nume_utilizator,adresa_email,comentariu) values('".$nume."','".$mail."','".$comentariu."')";
mysql_query($sql);
header("location: guestbook.php");
?>

I hope this will be useful to you. If you have any questions or problemns do not esitate to ask me.

 

 

 


Comment/Reply (w/o sign-up)

vietpost
Why should I waste one database for this tiny guestbook when I can download series of flat-text database php guestbook and upload to my server and use readily ?

Comment/Reply (w/o sign-up)

overture
you do not have to vietpost, dservice was just giving an alternate way to do it using MYSQL instead of the Flat file way to store information. if you do not want to use it, don't.

P.S. you get unlimited MYSQL Databases here at astahost!

Comment/Reply (w/o sign-up)

vietpost
Uhm, luckily we have unlimited databases here, but I've experienced with many free host providers who gimme only one database for all the applications I wish to use. Therefore, I suggest using flat-text database for programs which take not much information storage. Furthermore, to operate MySQL command, your host must have PhpMyAdmin, or some programs like that installed. This is unapplicable for most of our free host providers.

Comment/Reply (w/o sign-up)

overture
If you do not have phpMyAdmin installed or cannot access it you can call the commands from scripts, i have done that for my shoutbox editor. I am not sure if you can call everysingle MYSQL command that is available (possibly), but you can create databases and tables from scripts and add the required fields and so on.

Comment/Reply (w/o sign-up)

antitoxic
Good work dservice. It's great guestbook. And what does "comentarii" mean?!

Comment/Reply (w/o sign-up)

marijnnn
if anyone would be having problems with setting up the mysql database: i have a simple guestbook that uses a txt file to store the entries. it divides the entries in pages of 10 (you can easily adjust that by changing a constant in the beginning.
you can see a live demo on my site smile.gif www.lekstok.tk (and then go to guesjbook)
the site sucks, it was my first php site, 3 weeks after i bought my first php book, hehe. i had troubles setting up a database so it only uses files...

if anyone would be having problems with setting up the mysql database: i have a simple guestbook that uses a txt file to store the entries. it divides the entries in pages of 10 (you can easily adjust that by changing a constant in the beginning.
you can see a live demo on my site smile.gif www.lekstok.tk (and then go to guesjbook)
the site sucks, it was my first php site, 3 weeks after i bought my first php book, hehe. i had troubles setting up a database so it only uses files...

 

 

 


Comment/Reply (w/o sign-up)

Arbitrary
QUOTE
Uhm, luckily we have unlimited databases here, but I've experienced with many free host providers who gimme only one database for all the applications I wish to use. Therefore, I suggest using flat-text database for programs which take not much information storage. Furthermore, to operate MySQL command, your host must have PhpMyAdmin, or some programs like that installed. This is unapplicable for most of our free host providers.

Does it matter if you only have one database? You can always create multiple tables and give them different headers for different operations. I.e., you could have wp_users for wordpress users and ck_users for something else. It's a pretty easy fix, as long as they don't have a restrictive limit on the size of the database. Also, your host provides a database but no phpMyAdmin? Looks like it's time to switch to a paid host if you really want that kind of support. Don't expect it out of free hosts, and don't expect to run a database-driven website easily on most free hosts. They're free for a reason. Even Astahost isn't really "free", it expects you to compensate by posting in the forums. That's why it's so generous in providing features.

Of course, I do agree that most guestbooks don't need functionality that's inherently there in a database. It incurs quite a bit more overhead than needed. On the other hand, it's usually a lot more organized to keep your data all in one place.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for create, guestbook, php, create, guestbook
advertisement



How to create a guestbook with php !!! - Create your own guestbook.

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com