Page 1 of 1

Guestbook implementation

Posted: Sun Dec 27, 2009 9:55 am
by ZoeFken
Hello all i encounterd a problem wich i can't solve myself as i am no php wizard or any of that. I recently started on a website and a buddy of mine done the scripting in php but as he is out of the country for his work and won't be back for ages i am wondering if any of you would be able to assist me with the following problem. I whant to add a guestbook to a existing site / page system but it won't work for me. I tried it with a include or just plain copy paste add code thingy but everytime i try something the website gets kinda screwd :).

http://www.zoef-design.be/villa/en/guest.php this is what happens. Curently i don't have a guestbook running as it doesn't work with any of the guestbooks i tried it with. So i was hoping someone could give me some pointers or maybe a way wich would work.

Code of the page.

Code: Select all

<!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"><!-- InstanceBegin template="/Templates/mainTemplate.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<meta name="keywords" content="<?php echo $row['pageKeywords']; ?>" />
<meta name="description" content="<?php echo $row['pageDescription']; ?>" />
<title><?php echo $row['pageTitle']; ?> - <?php echo SITE_TITLE; ?></title>
<!-- InstanceEndEditable -->
<link href="../css/template.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>
 
<body>
<div id="mainContainer">
  <div id="headerContainer">
  <div class="langaugeNav">
    <ul>
    <?php
    $langSql = "SELECT lnId, name, flag FROM languages ORDER BY lnId DESC";
    $resultLang = query($langSql);
    while($rowLang = fetchArray($resultLang)) {
    ?>
      <li><a href="<?php echo  '../langaugeSelector.php?ac=selectLanguage&lnId=' . $rowLang['lnId'].'&file='.currentFile(); ?>"><img src="../images/flags/<?php echo $rowLang['flag']; ?>" width="20" height="13" alt="<?php echo $rowLang['name']; ?>" /></a></li>
    <?php } ?>
    </ul>
  </div>
  <br class="clear" />
    <div class="headerNavWarper">
      <ul>
        <li><a href="index.php"><?php echo HOME_LINK;?></a></li>
        <li><a href="gallery.php"><?php echo GALLERY_LINK;?></a></li>
        <li><a href="contact.php"><?php echo CONTACT_LINK;?></a></li>
    <li><a href="guest.php"><?php echo GUEST_LINK;?></a></li>
      </ul>
    </div>
    <br class="clear" />
  </div>
  <div id="container"><!-- InstanceBeginEditable name="container" -->
    <div class="leftPanel">
          <div class="pageHeading">
            <h1>Guestbook</h1>
          </div>
          <div class="pageText">
            <?php include("../guestbook/index.php"); ?>
              <br />
              <br />
            </p>
          </div>
        </div>
  <!-- InstanceEndEditable -->
    <div class="rightPanel">
      <div id="navContainer">
        <div class="navWarper">
          <ul>
          <?php 
          $sqlLinks = "SELECT pageId, pageTitle FROM staticpages WHERE isEnable = 0 AND lnId = ".LANGUAGE_ID ." ORDER BY recordListingID ASC";
            $resultLinks = query($sqlLinks);
            $numRowsLinks = numRows($resultLinks);
          if($numRowsLinks == 0){
               echo '<li>No Page Found.</li>';
          } else {
          while($rowLinks = fetchArray($resultLinks)) { 
          ?>
            <li><a href="page.php?p=<?php echo $rowLinks['pageId']; ?>"><?php echo $rowLinks['pageTitle']; ?></a></li>
          <?php }} ?>
          </ul>
        </div>
      </div>
      <div id="navContainerBottom"></div>
    </div>
    <br class="clear" />
  </div>
  <div id="containerBottom"></div>
  <div id="footer">Copyrights © 2009 All Rights Reserved By <strong><a href="#">Villa Bali Amber</a></strong><a href="#">.</a></div>
</div>
 
 
</body>
<!-- InstanceEnd --></html>
Tnx in advance for anything you can come up with.

Re: Guestbook implementation

Posted: Sun Dec 27, 2009 11:31 am
by kalidG
Hi this is the html code for the form that user can use to submit their Comments
i will provide for the php code

Code: Select all

 
<form action"your_page.php" method="POST"> <!--Page that handle the database additiion for example: let's make it simple you put the same page as this form -->
<fieldset>
<legend>Sign Guestbook</legend>
 
<label for="name">Name:</label>
<input name="name" id="name" maxlength="128" class="inputText" value="" type="text">
<br>
 
<label for="email">E-Mail Address:</label>
<input name="email" id="email" maxlength="256" class="inputText" value="" type="text">
<br>
    
<label for="url">Website URL:</label>
<input name="url" id="url" maxlength="512" class="inputText" value="" type="text">
<br>
 
<label for="comments">Comments:</label>
<textarea name="comments" id="comments" cols="40" rows="4" class="inputTextArea"></textarea>
<br>
 
<label for="electricsheep">Enter Code:</label>
<input name="electricsheep" id="electricsheep" maxlength="5" size="5" class="inputText" type="text">
<img src="index.php?action=challengeimage" alt="Challenge Image" class="challengeImage">
<br>
 
<input name="action" value="add" class="submit" type="hidden">
<input value="Add" class="submit" type="submit">
</fieldset>
</form>
 

Re: Guestbook implementation

Posted: Sun Dec 27, 2009 11:54 am
by kalidG
PHP code,
please note there are several way to do this

Code: Select all

 
<?php
//First let's connect to the database
$connection = mysql_connect("your server name goes here", "the username goes here", "the password goes here");
update_data();//we call it when page load
function update_data()
{
$update_query = "SELECT* from yourTableName ORDER BY id DSC";/*yourTableName: is the table in the database that contain the guestbook data*/
$guestbook = mysql_query($update_query, $connection) or die ("can't display the comments");
// display all the comments
while($row= mysql_fetch_array($guestbook)){
echo "<div class=\"comment\">";
echo"Name:<p class=\"name\">" .$row['name'] . "</p>";
echo"Comments:<p class=\"comment\">" .$row['comments'] . "</p>";
}
}
if(isset($_POST['submit'])){we will do do this only when the user submit the comment
//lets retrieve the sended variables via POST
$name = mysql_real_escape_string($_POST['name']); /*clean the name from slashes or other caracter tha may mess our data base up*/
$email = mysql_real_escape_string($_POST['email']);
$url = mysql_real_escape_string($_POST['url']);
$comments = mysql_real_escape_string($_POST['comments']);
//prepare the query
$query = "INSERT into yourTableName(name, email, url, comments) VALUES('{$name}', '{$email}', '{url}', '{comments}')";
//execute the query
mysql_query($query, $connection) or die ("sorry we coudln't add ur comments");
update_data();//let's update our page to display th new comment submitted
}
?>
 
ps: please not that this code will display all the comments not as sections like 1 2 3 4 last>
this will need some more work
and you can style the comment div etc.. i hope this is helpfull for you
foregive me if i miss-typed something or i missed something
No One Is Perfect

Re: Guestbook implementation

Posted: Sun Dec 27, 2009 1:12 pm
by ZoeFken
wich guestbook did you use to do this ? Wich sql settings where used ?

Re: Guestbook implementation

Posted: Sun Dec 27, 2009 4:39 pm
by kalidG
first question
"wich guest book did you use?"
i just come up with it it is a simple example
"wich sql setting i use"
i think u should give a cal to ur host to provide you with the data base account username and password and the server too

Re: Guestbook implementation

Posted: Sun Dec 27, 2009 6:50 pm
by ZoeFken
Thats not what i was talking about. I know my username and pasw and all the other things. What i was wondering was wich tables you made and so on and so fort. As i said my php knowladge lacks greatly and as that lacks also does my mysql :) I would greatly appreciate of anyone could use a existing php guestbook and explain to me how i can intigrate it into my existing website.

Tnx in advance.

Re: Guestbook implementation

Posted: Mon Dec 28, 2009 2:29 am
by kalidG
It is simple you just create a table with 4 field
name the table gustbook for example
an ID : type:INT(5) make it AUTOINCREMENT
Name: type :varchar and length make it 50 for example
email: type :varchar and make it 50 length
comments : type: text don't specify the lenght keep it blank

all that you can do it with phpMyAdmin on ur server