PX : code

Guestbook by Gwrx Liu Ronghua
Download this code


Below is the view and post your message.---reply_post_uevxs.php
==================================================================
<?php
//Thanks for the great php script of Matt
//Whitted(http://px.sklar.com/author.html?author_id=367)
//and Roger Eisenecher (http://www.icer.ch/php/icformgen/)
//I just modified and combined their script to fit my usage.
//I am not resposible for any errors or damages that cuased by this script.
//Below is mysql field
//+-----------+--------------+------+-----+---------+----------------+
//| Field     | Type         | Null | Key | Default | Extra          |
//+-----------+--------------+------+-----+---------+----------------+
//| id        | mediumint(8) |      | PRI | NULL    | auto_increment |
//| name      | varchar(30)  |      |     |         |                |
//| email     | varchar(30)  |      |     |         |                |
//| location  | varchar(30)  |      |     |         |                |
//| homepage  | varchar(30)  | YES  |     | NULL    |                |
//| message   | text         |      |     |         |                |
//| post_date | varchar(40)  | YES  |     | NULL    |                |
//| user      | varchar(10)  | YES  |     | NULL    |                |
//| reply     | varchar(30)  | YES  |     | NULL    |                |
//| reply2    | text         |      |     |         |                |
//+-----------+--------------+------+-----+---------+----------------+

echo "
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html;charset=big5\">
<meta http-equiv=\"Pragma\" content=\"no-cache\">

<title>Form input test</title>
</head> 

<body background=\"bg08.jpg\">
<p>Please sign your message<p>

"
;
 require(
"oohforms.inc");
    
$f = new form;


$f->add_element(array("type"=>"text",
                        
"name"=>"Name",
                        
"value"=>"",
                        
"valid_e"=>"Enter Your Name",
                        
"valid_regex"=>"^[-a-Az-Z0-9]*$"));
    
$f->add_element(array("type"=>"text",
                          
"name"=>"Email",
   
"valid_e"=>"Syntax Error in email address.",
       
"valid_regex"=>"^([-a-zA-Z0-9.]+@[-a-zA-Z0-9]+(\.[-a-zA-Z0-9]+)+)*$"));
        
$f->add_element(array("type"=>"text",
                                
"name"=>"Location"));
        
$f->add_element(array("type"=>"text",
                                
"name"=>"Homepage"
                                
));

  
$f->add_element(array("type"=>"textarea",
                          
"name"=>"Message",
                                
"rows"=>6,
                                
"cols"=>40,
                          
"value"=>""));



         
$f->add_element(array("type"=>"submit",

   
"name"=>"submitname"));

         
$f->add_element(array("type"=>"reset",
                          
"name"=>"resetname"));


    if (
$submitname) {

      if (
$err $f->validate()) {

        echo 
"Error";
        echo 
$err;

        
$f->load_defaults();


}
 }

    
$f->start("PHP_SELF","POST","reply_post_uevxs.php?user=uevxs");

echo 
"<center>Name:";
$f->show_element("Name");
echo 
"    Email: ";
$f->show_element("Email");
echo 
"<br>Location: ";

$f->show_element("Location");
echo
"      Homepage: ";
$f->show_element("Homepage");
   echo 
"\n<br>Message:<br> ";
    
$f->show_element("Message");
  echo 
"\n<br></center>";
 
$f->show_element("resetname",  "Reset");
    
$f->show_element("submitname""Submit");
    
$per_page 10;

$sql_text = ("select id,name,email,location,homepage,message,post_date,reply2 frrom guestbook  where user=('$user')order by id desc");
$t=0;

// Set page #, if no page isspecified, assume page 1
if (!$page) {
   
$page 1;
}
$prev_page $page 1;
$next_page $page 1;
    
mysql_connect("localhost","admin","admin");

mysql_select_db("guestbook")or die("Error opening database");
$postdate=date("F j, Y, g:i a");
/*if($submitname){
mysql_query("insert into guestbook (name,email,location,homepage,message,post_date,user)values('$Name','$Email','$Location','$Homepage','$Message','$postdate','uevxs')");
$query = mysql_query($sql_text);
$page_start = ($per_page * $page) - $per_page;
$num_rows = mysql_num_rows($query);

if ($num_rows <= $per_page) {
   $num_pages = 1;
} else if (($num_rows % $per_page) == 0) {
   $num_pages = ($num_rows / $per_page);
} else {
   $num_pages = ($num_rows / $per_page) + 1;
}
$num_pages = (int) $num_pages;
if (($page > $num_pages) || ($page < 0)) {
   error("You have specified an invalid page number");
}  

$sql_text = $sql_text ." LIMIT $page_start, $per_page";
$query = mysql_query($sql_text);
while (list($id,$Name,$Email,$Location,$Homepage,$Message,$post_date,$reply2) =mysql_fetch_array($query)){
echo "<hr>
$id.Date:$post_date<br>
Name:$Name &nbsp &nbsp &nbsp &nbsp<br>
                Email:<a href=\"mailto:$Email\">$Email</a><br>
        Location:$Location<br>
        Hompage:<a href=\"http://$Homepage\">$Homepage</a><br>
Message:$Message
<p>Reply:$reply2<hr>";

}
if ($prev_page)  {
   echo "<a href=\"$PHP_SELF?page=$prev_page\">Prev</a>";
}
for ($i = 1; $i <= $num_pages; $i++) {
   if ($i != $page) {
      echo " <a href=\"$PHP_SELF?page=$i\">$i</a> ";
   } else {
      echo "Page: $i ";
   }
}
if ($page != $num_pages) {
   echo "<a href=\"$PHP_SELF?page=$next_page\">Next</a>";
}

if($Name==""||$Email==""){
mysql_close();
}
 if ($submitname){
mysql_query("insert into guestbook (user)values('$user') where id=$reply");
}
$f->finish();

?>
</body></html>

Below is the administor's page---Reply3.php
<?php
echo "              
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html;charset=big5\">
<meta http-equiv=\"Pragma\" content=\"no-cache\">

<title>Form input test</title>
</head>
                    
<body>
<p>Reply to the guests<p>
";
    require("oohforms.inc");
    $f = new form;
 $f->add_element(array("type"=>"textarea",
                          "name"=>"reply2",
                           "value"=>"",
                           "rows"=>"6",
                          "cols"=>"25"  ));
        $f->add_element(array("type"=>"radio",
                        "name"=>"reply",
                        "value"=>$id
                                ));

         $f->add_element(array("type"=>"submit",
                          "name"=>"submitname"));
 $f->add_element(array("type"=>"submit",
                          "name"=>"submitname1"));
         $f->add_element(array("type"=>"reset",
  "name"=>"resetname"));


    if ($submitname) {

      if ($err = $f->validate()) {

        echo "Error";
        echo $err;

        $f->load_defaults();


}

 }
 $f->start("PHP_SELF","POST","reply3.php?user=$user");

echo "<center>Reply:";
      $f->show_element("reply2");
    echo "\n<br>";
echo "</center>";
$per_page = 10;
$sql_text = ("select id,name,email,location,homepage,message,post_date,reply2 from guestbook where user=('$user') order by id desc"); 
$t=0;

// Set page #, if no page isspecified, assume page 1
if (!$page) {
   $page = 1;
}
$prev_page = $page - 1;
$next_page = $page + 1;

mysql_connect("localhost","admin","admin");
mysql_select_db("guestbook")or die("Error opening database");
 if ($submitname){
mysql_query("update guestbook set reply2='$reply2' where id = $reply");
}
 if ($submitname1){
mysql_query("delete  from  guestbook where id = $reply");
}
$query = mysql_query($sql_text);
$page_start = ($per_page * $page) - $per_page;
$num_rows = mysql_num_rows($query);

if ($num_rows <= $per_page) {
   $num_pages = 1;
} else if (($num_rows % $per_page) == 0) {
   $num_pages = ($num_rows / $per_page);
} else {
   $num_pages = ($num_rows / $per_page) + 1;
}
$num_pages = (int) $num_pages;
if (($page > $num_pages) || ($page < 0)) {
   error("You have specified an invalid page number");
}  
$sql_text = $sql_text ." LIMIT $page_start, $per_page";
$query = mysql_query($sql_text);

while (list($id,$Name,$Email,$Location,$Homepage,$Message,$post_date,$reply2) =

$f->show_element("reply",$id);
echo "<p>$id
Date:$post_date<br>
Name:$Name &nbsp &nbsp &nbsp &nbsp<br>
                Email:<a href=\"mailto:$Email\">$Email</a><br>
        Location:$Location<br>
        Hompage:<a href=\"http://$Homepage\">$Homepage</a><br>
Message:$Message
<p>Reply:$reply2<hr>";

}
if ($prev_page)  {
   echo "<a href=\"$PHP_SELF?page=$prev_page\">Prev</a>";
}
for ($i = 1; $i <= $num_pages; $i++) {
   if ($i != $page) {
      echo " <a href=\"$PHP_SELF?page=$i\">$i</a> ";
   } else {
      echo "Page: $i ";
   }
}
if ($page != $num_pages) {
   echo "<a href=\"$PHP_SELF?page=$next_page\">Next</a>";
}

$f->show_element("resetname",  "Reset");
    $f->show_element("submitname", "Submit");
   $f->show_element("submitname1", "Delete");
/* if ($submitname){
mysql_query("insert into guestbook (user)values('$user') where id=$reply");
}*/
$f->finish();

?>
</body></html>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.