Jump to content

A Simple & Basic GUEST BOOK...


aamberker

Recommended Posts

Hi All :) Hey friends.... I would like to design a Simple & Basic GUEST BOOK in PHP...I have geared-up the HTML file but not sure what to place in ".php" file... whewwww!!!!... And moreover not sure which additional files I need to upload along with .HTML and .PHP files...Please help.Look forward to hearing from you.Thanks.

Link to comment
Share on other sites

Basically here's what you're going to need for the simplest guestbook ever:1: HTML form with whatever fields you like, Name, Email, comment text etc;2: PHP page to handle the form submission from the HTML page;3: A database and table that will hold all information. Google database structures and column. In fact, google Guestbook scripts in PHP(Try google code actually). That should help you.

Link to comment
Share on other sites

Basically here's what you're going to need for the simplest guestbook ever:1: HTML form with whatever fields you like, Name, Email, comment text etc;2: PHP page to handle the form submission from the HTML page;3: A database and table that will hold all information. Google database structures and column. In fact, google Guestbook scripts in PHP(Try google code actually). That should help you.
Heyy Dude,Thank you for your response but you need to help me in this... Following is the HTML Code of my simple GuestBook... Well, now what should I place in "backend.php" file??? Hey... You need to help me to fish-out the database structures and column in Google... :)********************<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><form id="form1" name="form1" method="post" action="backend.php"> <table width="500" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="92">Name:</td> <td width="408"><input name="name" type="text" id="name" /></td> </tr> <tr> <td valign="top">Comments:</td> <td><textarea name="comments" rows="5" id="comments"></textarea></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Submit" />   |   <input name="reset" type="reset" id="reset" value="Reset" /></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td>oooOoooOoooOoooOoooOoooOoooOoooOoooOoooOoooO</td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> </tr> </table></form></body></html>
Link to comment
Share on other sites

Ok, the first thing in backend.php you are going to need to do is this:

$name = (isset($_POST['name'])) ? $_POST['name'] : false;$contents = (isset($_POST['comments']) ? $_POST['comments'] : false;//This checks if those 2 fields are set, if not, return false into $name;if(!$name || !$contents){ //Simple if, if the inversion of $contents or $name is true(ie, it would have to be false), die out an error  die("You must submit all fields. Please, go back and fill in any fields that you may have left empty.");}

Thats a good place to start. You first need to make sure your host has a database available to it, and if it does you need to figure out the login(username, host address, and password) to connect to, and create your database. If your house doesn't have a database, you can still use a guestbook, you'll just have to use a flat-file system instead.

Link to comment
Share on other sites

Ok, the first thing in backend.php you are going to need to do is this:
$name = (isset($_POST['name'])) ? $_POST['name'] : false;$contents = (isset($_POST['comments']) ? $_POST['comments'] : false;//This checks if those 2 fields are set, if not, return false into $name;if(!$name || !$contents){ //Simple if, if the inversion of $contents or $name is true(ie, it would have to be false), die out an error  die("You must submit all fields. Please, go back and fill in any fields that you may have left empty.");}

Thats a good place to start. You first need to make sure your host has a database available to it, and if it does you need to figure out the login(username, host address, and password) to connect to, and create your database. If your house doesn't have a database, you can still use a guestbook, you'll just have to use a flat-file system instead.

Hi Jhecht :)Hey... Thank you for your response.Well, as per your feedback I have paste the following CODE in "backend.php" file... ************************************$name = (isset($_POST['name'])) ? $_POST['name'] : false;$contents = (isset($_POST['comments']) ? $_POST['comments'] : false;//This checks if those 2 fields are set, if not, return false into $name;if(!$name || !$contents){//Simple if, if the inversion of $contents or $name is true(ie, it would have to be false), die out an error die("You must submit all fields. Please, go back and fill in any fields that you may have left empty.");}************************************Well, now what next??? Should I need to upload HTML and PHP files?? By the way, where should I mention the file name of HTML in the above PHP Code??? Perhaps I can just send you the HTML and PHP files if you could let me know your email ID :)Look forward to hearing from you soon...
Link to comment
Share on other sites

Should I need to upload HTML and PHP files??
You need to place the PHP file on a server (either local or remote) that has PHP support, or else the PHP code won't run.
By the way, where should I mention the file name of HTML in the above PHP Code???
You won't need to, in the form submit field on your HTML page with the guestbook form, you set the form action attribute to "backend.php", and the HTML form 'posts' the guestbook entry to the PHP script, and no further reference is needed.
Well, now what next???
Before you go any further, I suggest you find a server with PHP and a database system, preferably mySQL. Then, read up about mySQL, and create a database and a table to store the guestbook entries. After you have done that, then you can read up about mySQL http://www.w3schools.com/php/php_mysql_intro.asp and see what you can do by yourself :) Come back if you have any questions.
Link to comment
Share on other sites

Agreed, Synook.Assuming you run this query on your database(assuming you have one) first:

CREATE TABLE guestbook(entry_id int unique not null auto_increment, entry_ip varchar(15) not null, entry_name varchar(125) not null,entry_comment TEXT,FULLTEXT('entry_comment'));

You would then do something like

$name = (get_magic_quotes_gpc()) ? $name : mysql_real_escape_string($name);$contents = (get_magic_quotes_gpc())?$contents:mysql_real_escape_string($contents);$user_ip = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : $HTTP_SERVER_VARS['REMOTE_ADDR'];$msa = mysql_connect('localhost','user','pass') or die("Could not connect to mysql<br />".mysql_error());@mysql_select_db('db',$msa) or die("Could not select Database<br />".mysql_error());$sql = "INSERT INTO guestbook(entry_id,entry_ip,entry_name,entry_comment) VALUES(NULL,'$user_ip','$name','$contents')";$ans=mysql_query($sql,$msa) or die(mysql_error()." on line ".__LINE__." in file ".__FILE__);//If the script reaches here, we can assume that the query didn't mess up or die out. Redirect to wherever you want. change yourPage.html to whatever you needusleep(500);//I've noticed that unless you use usleep if you use header(location) it forces the _POST or _GET data on the relocated page;header('location:yourPage.html');//End script

Link to comment
Share on other sites

You need to place the PHP file on a server (either local or remote) that has PHP support, or else the PHP code won't run.You won't need to, in the form submit field on your HTML page with the guestbook form, you set the form action attribute to "backend.php", and the HTML form 'posts' the guestbook entry to the PHP script, and no further reference is needed.Before you go any further, I suggest you find a server with PHP and a database system, preferably mySQL. Then, read up about mySQL, and create a database and a table to store the guestbook entries. After you have done that, then you can read up about mySQL http://www.w3schools.com/php/php_mysql_intro.asp and see what you can do by yourself :) Come back if you have any questions.
**********************************************Hey Synook :)Thank you for your response…Well…--- You need to place the PHP file on a server (either local or remote) that has PHP support, or else the PHP code won't run. ---Okay… I got it!!!… Please pull the following URL – www.mirroremage.com :blink: … That’s my personal site and it does support PHP :)--- You won't need to, in the form submit field on your HTML page with the guestbook form, you set the form action attribute to "backend.php", and the HTML form 'posts' the guestbook entry to the PHP script, and no further reference is needed. ---Ohh!!!... hummmmm… OKAY!!!.. I got it… I thought perhaps I need mention the file name of HTML in PHP Code… hummmmmm… Yeah!!!... It’s not required… YUP!!!.. GOT THAT!!!...--- Before you go any further, I suggest you find a server with PHP and a database system, preferably mySQL. Then, read up about mySQL, and create a database and a table to store the guestbook entries. After you have done that, then you can read up about mySQL http://www.w3schools.com/php/php_mysql_intro.asp and see what you can do by yourself Come back if you have any questions. ---As I said above, I do have server which supports PHP and hence NO WORRIES!!!… I pay for my Domain and Web Space every year… But hey… I cannot read this - http://www.w3schools.com/php/php_mysql_intro.asp ..... Since it’s not my cup of tea and moreover I cannot understand those technical terms and slang.WELL, NOW WHAT NEXT?Look forward to hearing from you…
Link to comment
Share on other sites

Agreed, Synook.Assuming you run this query on your database(assuming you have one) first:
CREATE TABLE guestbook(entry_id int unique not null auto_increment, entry_ip varchar(15) not null, entry_name varchar(125) not null,entry_comment TEXT,FULLTEXT('entry_comment'));

You would then do something like

$name = (get_magic_quotes_gpc()) ? $name : mysql_real_escape_string($name);$contents = (get_magic_quotes_gpc())?$contents:mysql_real_escape_string($contents);$user_ip = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : $HTTP_SERVER_VARS['REMOTE_ADDR'];$msa = mysql_connect('localhost','user','pass') or die("Could not connect to mysql<br />".mysql_error());@mysql_select_db('db',$msa) or die("Could not select Database<br />".mysql_error());$sql = "INSERT INTO guestbook(entry_id,entry_ip,entry_name,entry_comment) VALUES(NULL,'$user_ip','$name','$contents')";$ans=mysql_query($sql,$msa) or die(mysql_error()." on line ".__LINE__." in file ".__FILE__);//If the script reaches here, we can assume that the query didn't mess up or die out. Redirect to wherever you want. change yourPage.html to whatever you needusleep(500);//I've noticed that unless you use usleep if you use header(location) it forces the _POST or _GET data on the relocated page;header('location:yourPage.html');//End script

---------------------------------------------------------------Hi Again Jhecht...Thanks for your response...--- Assuming you run this query on your database(assuming you have one) first:CODECREATE TABLE guestbook(entry_id int unique not null auto_increment, entry_ip varchar(15) not null, entry_name varchar(125) not null,entry_comment TEXT,FULLTEXT('entry_comment')); ---:) ... I guess I am unable to understand that but let me try :) ... Well, do I need to place the above CODE in ".txt" and upload the same along with HTML and PHP files??? Am I making sense???--- You would then do something like CODE$name = (get_magic_quotes_gpc()) ? $name : mysql_real_escape_string($name);$contents = (get_magic_quotes_gpc())?$contents:mysql_real_escape_string($contents);$user_ip = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : $HTTP_SERVER_VARS['REMOTE_ADDR'];$msa = mysql_connect('localhost','user','pass') or die("Could not connect to mysql<br />".mysql_error());@mysql_select_db('db',$msa) or die("Could not select Database<br />".mysql_error());$sql = "INSERT INTO guestbook(entry_id,entry_ip,entry_name,entry_comment) VALUES(NULL,'$user_ip','$name','$contents')";$ans=mysql_query($sql,$msa) or die(mysql_error()." on line ".__LINE__." in file ".__FILE__);//If the script reaches here, we can assume that the query didn't mess up or die out. Redirect to wherever you want. change yourPage.html to whatever you needusleep(500);//I've noticed that unless you use usleep if you use header(location) it forces the _POST or _GET data on the relocated page;header('location:yourPage.html');//End script ---whewwwwww!!!!.. HEYYY DUDE, WHAT IS THAT NOW??? WHERE DO I NEED TO PASTE THAT??? It's indeed confusing a lot :)Look forward to hearing from you...
Link to comment
Share on other sites

the create table statement is run on your MySQL server. On your webhost look for something called phpMyAdmin and copy paste that first line into it.The code i gave you otherwise is to be added after the first bit of code i originally gave you. If you dont have MySQL, then we are going to have to alter this to work for flat-file systems, which are a bit more annoying, but you have to use what is available to you.

Link to comment
Share on other sites

the create table statement is run on your MySQL server. On your webhost look for something called phpMyAdmin and copy paste that first line into it.The code i gave you otherwise is to be added after the first bit of code i originally gave you. If you dont have MySQL, then we are going to have to alter this to work for flat-file systems, which are a bit more annoying, but you have to use what is available to you.
------------------------------------------------------------------------------Hi Again Jhecht...Thanks a ton for your response...--- the create table statement is run on your MySQL server. On your webhost look for something called phpMyAdmin and copy paste that first line into it. --- Well, OKAY!!!.. I will try to fish-out for "phpMyAdmin" file... I hope it's a Name of a "file"...--- The code i gave you otherwise is to be added after the first bit of code i originally gave you. If you dont have MySQL, then we are going to have to alter this to work for flat-file systems, which are a bit more annoying, but you have to use what is available to you. ---Well, then the final CODE will be like this - RIGHT???**********************************$name = (isset($_POST['name'])) ? $_POST['name'] : false;$contents = (isset($_POST['comments']) ? $_POST['comments'] : false;//This checks if those 2 fields are set, if not, return false into $name;if(!$name || !$contents){//Simple if, if the inversion of $contents or $name is true(ie, it would have to be false), die out an error die("You must submit all fields. Please, go back and fill in any fields that you may have left empty.");}$name = (get_magic_quotes_gpc()) ? $name : mysql_real_escape_string($name);$contents = (get_magic_quotes_gpc())?$contents:mysql_real_escape_string($contents);$user_ip = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : $HTTP_SERVER_VARS['REMOTE_ADDR'];$msa = mysql_connect('localhost','user','pass') or die("Could not connect to mysql<br />".mysql_error());@mysql_select_db('db',$msa) or die("Could not select Database<br />".mysql_error());$sql = "INSERT INTO guestbook(entry_id,entry_ip,entry_name,entry_comment) VALUES(NULL,'$user_ip','$name','$contents')";$ans=mysql_query($sql,$msa) or die(mysql_error()." on line ".__LINE__." in file ".__FILE__);//If the script reaches here, we can assume that the query didn't mess up or die out. Redirect to wherever you want. change yourPage.html to whatever you needusleep(500);//I've noticed that unless you use usleep if you use header(location) it forces the _POST or _GET data on the relocated page;header('location:yourPage.html');//End script ---**********************************Oh!!... hummmmm... Let's hope that my webhost do have "MySQL"... However could you tell me about how do I check whether "MySQL" is there or nope??? Heyy.... By the way, my site is - www.mirroremage.com :)Look forward to hearing from you...
Link to comment
Share on other sites

Make a file with only this in it and save it as a PHP file:<?php phpinfo(); ?>If you run the file in a browser you will see the PHP configuration. If you scroll down you should see a list of options for the mysql extension. If you do not see the mysql extension listed, then it is not set up.Also, phpMyAdmin is not a file, it's a program. You can download it and install it yourself, or your host might provide it for you through a control panel.

Link to comment
Share on other sites

Make a file with only this in it and save it as a PHP file:<?php phpinfo(); ?>If you run the file in a browser you will see the PHP configuration. If you scroll down you should see a list of options for the mysql extension. If you do not see the mysql extension listed, then it is not set up.Also, phpMyAdmin is not a file, it's a program. You can download it and install it yourself, or your host might provide it for you through a control panel.
--------------------------------------------------------------------------------Hi Justsomeguy,Thank you for your response...As per your feedback I made a file and copied just <?php phpinfo(); ?> in it and saved it as a PHP file. Please pull the followign URL - http://www.mirroremage.com/PHP.phpWELL, NOW WHAT NEXT?Look forward to hearing from you soon...
Link to comment
Share on other sites

The mysql extension is listed, so PHP has support for MySQL. You have this line of code:$msa = mysql_connect('localhost','user','pass') or die("Could not connect to mysql<br />".mysql_error());If you aren't seeing that error message, then the MySQL server is running.

Link to comment
Share on other sites

The mysql extension is listed, so PHP has support for MySQL. You have this line of code:$msa = mysql_connect('localhost','user','pass') or die("Could not connect to mysql<br />".mysql_error());If you aren't seeing that error message, then the MySQL server is running.
-------------------------Thank you for confirming that the mysql extension is listed, so PHP has support for MySQL. You mean, the following CODE:$msa = mysql_connect('localhost','user','pass') or die("Could not connect to mysql<br />".mysql_error());will be displayed in [http://www.mirroremage.com/PHP.php] somewhere at the bottom??? Am I making sense?Look forward to hearing from you.
Link to comment
Share on other sites

No, the line of code I pasted is in the block of code you pasted before.Look at the reference for MySQL, you will see an example of how to connect to the database. If you can connect, then it's running.http://www.php.net/manual/en/function.mysql-connect.phpIf you check the reference for mysql_query you'll see how to connect to and use the database.

Link to comment
Share on other sites

No, the line of code I pasted is in the block of code you pasted before.Look at the reference for MySQL, you will see an example of how to connect to the database. If you can connect, then it's running.http://www.php.net/manual/en/function.mysql-connect.phpIf you check the reference for mysql_query you'll see how to connect to and use the database.
-----------------Thank you for your response but too too too difficult to understand :) ... Perhaps Jhecht will be able to help me out... Just patiently waiting for Jhecht to pop-up...Do you use Yahoo Messenger or Skype or something like that???
Link to comment
Share on other sites

I don't use instant messaging for support like this, I'm sorry. This forum is really here to help people learn how to do something, not to do it for them. There are forums where you can post job requests that you have and need done, this just isn't one of them. If you want to learn how to do this we can help you learn how, but don't expect someone to write everything for you.

Link to comment
Share on other sites

If you find jumping straight into writing a questbook script too difficult, why don't you first try something simpler, like first getting a single post value from one page to another, then try simple SELECT and INSERT queries, until eventually you can fulfil your requirements all by yourself? :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...