Guest Book

Page 1 of 1

1 Replies - 374 Views - Last Post: 27 December 2009 - 06:21 PM

#1 dbfootballa3  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 238
  • Joined: 24-November 05

Guest Book

Posted 16 January 2006 - 05:12 PM

Description: Edit the config variablesSimple MySql Guestbook
<form name="form1" method="post" action="<?=$_SERVER['PHP_SELF'] ?>">
  <table width="50%"  border="0">
    <tr>
      <td>Name</td>
      <td><input name="name" type="text" id="name"></td>
    </tr>
    <tr>
      <td>Email or WebSite </td>
      <td><input name="link" type="text" id="link" value="http://"></td>
    </tr>
    <tr>
      <td>Body</td>
      <td><textarea name="body" cols="25" rows="7"></textarea></td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="submit" name="Submit" value="Submit">
          <input type="reset" name="Submit2" value="Reset"></td>
    </tr>
  </table>
</form>
<?php
/*USE THIS MYSQL CODE

CREATE TABLE `guest` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` TEXT NOT NULL ,
`link` TEXT NOT NULL ,
`body` TEXT NOT NULL ,
`date` TEXT NOT NULL
PRIMARY KEY ( `id` )
) TYPE = MYISAM ;

*/

#--MySql Configuration--#
$sql_host = "localhost";     //Host name of server usually 'localhost'
$sql_name = "root";          //Username for MySql
$sql_pass = "";     //Pasword for MySql
$sql_db = "dlink";     //Database

if($_POST['name'] != "" && $_POST['body'] != "") {     //Let's make sure the person put something in...

     if(mysql_connect($sql_host, $sql_name, $sql_pass) && mysql_select_db($sql_db)) {     //Let's make sure we can connect
     
     #Just some variables#
     $name = addslashes(strip_tags($_POST['name']));
     $link = addslashes(strip_tags($_POST['link']));
     $body = addslashes(strip_tags($_POST['body']));
     $date = date("F j, Y. g:i A");
     
     $query = "INSERT INTO `guest` (name,link,body,date) VALUES('$name','$link','$body','$date')";     //Insert the data into the table.
     mysql_query($query);
     
     $redir = $_SERVER['PHP_SELF'];
     
     echo "Thank you for signing my guest book!";
     echo "<meta http-equiv='refresh' content='1; $redir'>";
     
     } else {
     die(mysql_error());
     }

}

if(mysql_connect($sql_host, $sql_name, $sql_pass) && mysql_select_db($sql_db)) {     //Start to show all the entrys

     $show = "SELECT * FROM `guest` ORDER BY `id` DESC LIMIT 10";     //Only show 10 posts.
     $show = mysql_query($show);
     
          echo "<table>";
     
     while($row = mysql_fetch_array($show)) {     //Loop this to get all possible posts.
     
     echo "<tr><td><strong><a href='". $row['link'] ."'>". $row['name'] . "</a></strong></td><td>". $row['date'] . "</td></tr>";
     echo "<tr><td>". $row['body'] ."</td></tr><td><td></td></tr>";
     
     
     }
     
          echo "</table>";

} else {

die(mysql_error());

}
?>


Is This A Good Question/Topic? 0
  • +

Replies To: Guest Book

#2 bhuvaneswari  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-June 08

Re: Guest Book

Posted 27 December 2009 - 06:21 PM

if($_POST['name'] != "" && $_POST['body'] != "") what to put inside this tag " ".. its showing errror....... please update ..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1