A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Guestbook PHP help needed

  1. #1
    Grandfather to the stars bigginge's Avatar
    Join Date
    Oct 2003
    Location
    UK
    Posts
    735

    Guestbook PHP help needed

    I recently built a site incorporating the Flash-DB Guestbook as a forum, run by a PHP script. The customer has now asked if I can remove the users email addresses from the guestbook, but keep them in the notification email they receive. I don't know much about PHP and normally I'd try a few things until I worked it out, but as the site is live, and I don't want to screw the guestbook up, I'm a bit stuck. The PHP code is:
    Code:
    <?
    /* 
    -----
    Application: Flash-dB GuestBook Version 2.0
    Details:     mySQL and PHP powered GuestBook
    Author:      Mohsin Sumar
    Website:     http://www.flash-db.com
    Support:     http://www.flash-db.com/Board
    Notes:       Coments are marked by using comment entries symbols. Eg: // Comment
    -----
    */
    
    // Part One - Initiate a mySQL Database Connection
    // Database Connectivity Variables and other Variables
       $DBhost = "localhost";   // Database Server
       $DBuser = "northant_nvtwin";            // Database User
       $DBpass = "HaRlEy7";            // Database Pass
       $DBName = "northant_guestbook";            // Database Name
       $table = "guestbook";             // Database Table
       $numComments = 10;       // Number of Comments per page
       
       // Connect to mySQL Server
       $DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error in GuestBook Application: " . mysql_error());
       // Select mySQL Database
       mysql_select_db($DBName, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
    
    // Part Two - Choose what action to perform
       $action = $_GET['action'];
       
       switch($action) {
          case 'read' :
    		 // Fetch all comments from database table
    		 $sql = 'SELECT * FROM `' . $table . '`';
    		 $allComments = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
    		 $numallComments = mysql_num_rows($allComments);
    		 // Fetch page-wise comments from database table
    		 $sql .= ' ORDER BY `time` DESC LIMIT ' . $_GET['NumLow'] . ', ' . $numComments;
    		 $fewComments = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
    		 $numfewComments = mysql_num_rows($fewComments);
    		 // Generate Output for Flash to Read
    		 print '&totalEntries=' . $numallComments . '&';
    		 print "<br>&entries=";	
    		 
    		 if($numallComments == 0) {
    		    print "No entries in the guestbook, as yet..";
    		 } else { 
    		    while ($array = mysql_fetch_array($fewComments)) {
    			   $name = mysql_result($fewComments, $i, 'name');
    			   $email = mysql_result($fewComments, $i, 'email');
    			   $comments = mysql_result($fewComments, $i, 'comments');
    			   $time = mysql_result($fewComments, $i, 'time');
    			   
    			   print '<b>Name: </b>' . $name . '<br><b>Email: </b>' . $email . '<br><b>Comments: </b>' . $comments . '<br><i>Date: ' . $time . '</i><br><br>';
    			   $i++;
    		    }
    		}
    		// Print this only when there aren't any more entries..
    		if($_GET['NumLow'] > $numallComments) {
    		   print 'No More Entries!&';
    		}
    		break;
    		 
    	  case 'write' :
    	     // Recieve Variables From Flash
    		 $name = ereg_replace("&", "%26", $_POST['yourname']);
    		 $email = ereg_replace("&", "%26", $_POST['youremail']);
    		 $comments = ereg_replace("&", "%26", $_POST['yourcomments']);
    		 $submit = $_POST['submit'];
    		 	 				   $bad_words = explode('|', 'bugger|mutha****er|bollocks|****|****|****er|****ing|cock|cocksucker');
    foreach ($bad_words as $naughty)
    {
    $comments = eregi_replace($naughty, "word removed", $comments);
    }
    		 // Current system date in yyyy-mm-dd format
    		 $submitted_on = date ("Y-m-d H:i:s",time());
    		 		 
    		 // Check if its submitted from Flash
    		 if($submit == 'Yes'){
    		 // Insert the data into the mysql table
    		 $sql = 'INSERT INTO ' . $table . 
                    ' (`ID`, 
    				   `name`, 
    				   `email`, 
    				   `comments`, 
    				   `time`
    				  ) 
    				  VALUES 
    				  (\'\','
    				   . '\'' . $name . '\',' 
    				   . '\'' . $email . '\',' 
    				   . '\'' . $comments . '\',' 
    				   . '\'' . $submitted_on . '\'
    				   )';
    				   
    
    		 $insert = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
    		 
    		 // If you want your script to send email to both you and the guest, uncomment the following lines of code
    		 // Email Script Begin
    		
    		$MyName = "NVT";
    		 $MyEmail = "user@someone.co.uk";
    		 $Subject = "$name has just posted on the forum.";
    		 $EmailBody = "Hello NVT,\n$name has just signed the forum at http://www.northantsvtwin.co.uk. The following were the details submitted:\n\nName: $name\nEmail: $email\nComment:\n$comments\n";
    		 
    		 $EmailFooter = "~~~~~~~~~~~~~~~\nThe guestbook was signed by $name and thus this email got activated by $name from $REMOTE_ADDR from http://www.northantsvtwin.co.uk\n~~~~~~~~~~~~~~~\nThank you,\nNVT";
    		 
    		 $Message = $EmailBody.$EmailFooter;
    		 
    		 mail($MyName." <".$MyEmail.">",$Subject, $Message, "From: ".$name." <".$email.">");
    		 // Email Script End
    		 
    		 print "&gb_status=Thank you for signing the guestbook.&done=yes&";
    		 return;
    		 }
    		 print "&_root.write.gb_status=Error!&";
    		 break;
       }
    ?>
    I would be most grateful for any help.
    To dance beneath the diamond sky with one hand waving free
    Love Light Romania Romania Blog

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    it is only this line
    Code:
    print '<b>Name: </b>' . $name . '<br><b>Email: </b>' . $email . '<br><b>Comments: </b>' . $comments . '<br><i>Date: ' . $time . '</i><br><br>';
    that determines the display. Now, if you feel scared by a live system, leave the old one in place while <ou add the new one:
    Code:
    #print '<b>Name: </b>' . $name . '<br><b>Email: </b>' . $email . '<br><b>Comments: </b>' . $comments . '<br><i>Date: ' . $time . '</i><br><br>';
    print '<b>Name: </b>' . $name . '<br><b>Comments: </b>' . $comments . '<br><i>Date: ' . $time . '</i><br><br>';
    So it is easier to revert the change

    Musicman

  3. #3
    Grandfather to the stars bigginge's Avatar
    Join Date
    Oct 2003
    Location
    UK
    Posts
    735
    Brilliant. It also cleared all previous email addresses, so I guess it writes it all out new each time.
    Thank you for your help.
    To dance beneath the diamond sky with one hand waving free
    Love Light Romania Romania Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center