I'm new to PHP and my Guestbook is failing big time...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sylvia
Forum Newbie
Posts: 3
Joined: Sat Aug 30, 2008 8:33 pm
Location: Laval, QC, CANADA

I'm new to PHP and my Guestbook is failing big time...

Post by Sylvia »

http://www.php-mysql-tutorial.com/mysql ... k.php#sign

this is the tutorial i used for my guestbook, only I don't understand where to put what. And I'm going completely out of my mind trying to understand. I think I've been working on this for the past 2 weeks!

This is what I have for 'config.php' :

Code: Select all

 
<?php 
 
$dbhost= 'hostname';
$dbuser= 'myusername';
$dbpass= 'mypassword';
$dbname= 'database_registered_w/_my_server';
 
?>
 
Now what I'm wondering is if my coding is correct and if I have to put this code into the body of an HTML based file and just call it 'config.php'? Or is it simply just THAT code exactly that I call 'config.php' to use later on?

***MANY OTHER QUESTIONS TO COME***
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: I'm new to PHP and my Guestbook is failing big time...

Post by andyhoneycutt »

In the example that you refer to, the information in both config.php and opendb.php should be saved each as separate files (config.php, and opendb.php). You will include them in your code, from what the example shows, later in the lesson. The author of that article has supplied links to both files (ending with "s" meaning "source"). You can save those files as-is with just the ".php" extension. You will need to make modifications at least to "config.php" in order to properly connect to your datasource(s).

-Andy
Sylvia
Forum Newbie
Posts: 3
Joined: Sat Aug 30, 2008 8:33 pm
Location: Laval, QC, CANADA

Re: I'm new to PHP and my Guestbook is failing big time...

Post by Sylvia »

thx, now i understand that part!

Question 2:
My page with the form is on this page: 'gbookform.html'
My page with the form action: 'post.php',
Page with the entries: guestbook.php
Pages saved separately: config.php & opendb.php
Where does these next codes go?

CodeA:

Code: Select all

<?php
 
// how many guestbook entries to show per page
$rowsPerPage = 25;
 
// by default we show first page
$pageNum = 1;
 
if(isset($_GET['page']))
{
 $pageNum = $_GET['page'];
}
 
$offset = ($pageNum - 1) * $rowsPerPage;
 
// prepare the query string
$query = "SELECT id,
                 name,
                 comments,
                 DATE_FORMAT(entry_date, '%d.%m.%Y') ".
             "FROM guestbook ".
             "ORDER BY id DESC ".
             "LIMIT $offset, $rowsPerPage";
 
// ... the rest of the code
?>
This above one I'm guessing on my guestbook.php page but I'm not sure at all. If so, where? Do I put it in the heading or the body?

CodeB:

Code: Select all

<?php
// .... previous code
 
$query    = "SELECT COUNT(id) AS numrows FROM guestbook";
$result   = mysql_query($query) or die('Error, query failed');
$row      = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows  = $row['numrows'];
 
$maxPage  = ceil($numrows/$rowsPerPage);
$nextLink = '';
 
if($maxPage > 1)
{
   $self = $_SERVER['PHP_SELF'];
 
   $nextLink = array();
 
   for($page = 1; $page <= $maxPage; $page++)
   {
      $nextLink[] = "<a href=\"$self?page=$page\">$page</a>";
   }
 
   $nextLink = "Go to page : " . implode(' &raquo; ', $nextLink);
}
 
include 'library/closedb.php';
?>
<table width="550" border="0" cellpadding="2" cellspacing="0">
<tr>
<td align="right" class="text">
<?=$nextLink;?>
</td>
</tr>
</table>
This above code includes the page 'closedb.php', I don't know what's suppose to be on that page because it's not really mentioned at all in the tutorial.

Thx for the upcoming replies!
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: I'm new to PHP and my Guestbook is failing big time...

Post by andyhoneycutt »

I haven't read the entire article that you are referencing here, however I am sure the opendb.php page will be referenced by another page in your web application, either with an include statement or a require statement.

I would suggest going through the article step-by-step and verifying that you've done what the author is doing before proceeding any further. I'm willing to help with any questions you may have concerning the code itself, but I am sure if you follow through the article you will find all of your pages landing in the right spot.

Please go through the article again and if you have any questions regarding how the code works, or any questions about logic, I'd be more than willing to answer them here for you.

Thanks,
Andy.
User avatar
starram
Forum Commoner
Posts: 58
Joined: Thu Apr 10, 2008 1:27 am
Location: India
Contact:

Re: I'm new to PHP and my Guestbook is failing big time...

Post by starram »

Could you please explain what u want to do?
Post Reply