Welcome, Guest. Please login or register.
Did you miss your activation email?
05/21/12, 03:00
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  Recent Tutorial Support
| |-+  Flash GuestBook Support (Moderators: Flash-db, vesa kortelainen, Ronald Wernecke, Mohsin Sumar, Jorge Solis)
| | |-+  Guestbook Admin
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 Print
Author Topic: Guestbook Admin  (Read 30742 times)
Jamie SJ
Server what's that
*
Posts: 3



View Profile Email
« on: 09/24/04, 01:30 »

Some of you might be interested in this. I modified the Guestbook v2 script so that you can use an administration tool to edit or delete the entries. Here's the code for the Guestbook.php file:

<?
/*
-----
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 = "yourDBuser";            // Database User
  $DBpass = "yourDBpassword";            // Database Pass
  $DBName = "yourDBname";            // Database Name
  $table = "guestbook";             // Database Table
  $numComments = $_GET['numComments'];       // 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'];
          
       // 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
      
          /* <-- Remove this line
         $MyName = "Mohsin Sumar";
         $MyEmail = "mohsinsumar@hotmail.com";
          $Subject = "$name has just signed your guestbook.";
         $EmailBody = "Hello Mohsin,\n$name has just signed your guestbook available at http://www.mohsinsumar.com. THe following were the details submitted into your guestbook:\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.mohsinsumar.com\n~~~~~~~~~~~~~~~\nThanking you,\nMohsin Sumar";
      
          $Message = $EmailBody.$EmailFooter;
      
          mail($MyName." <".$MyEmail.">",$Subject, $Message, "From: ".$name." <".$email.">");
          --> Remove this line */
      
          // Email Script End
      
          print "&gb_status=Thank you for signing my guestbook.&done=yes&";
          return;
       }
       print "&_root.write.gb_status=Error!&";
       break;
      
   case 'edit' :
        // 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'];
       $entryNum = $_POST['entryNum'];
             
       // Check if its submitted from Flash
       if($submit == 'Yes'){
          $sql = "SELECT * FROM $table ORDER BY `ID` DESC LIMIT " . $_GET['NumLow'] . ", " . $numComments;
         $fewComments = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
          $id = mysql_result($fewComments, 0, 'ID');
          // Insert the data into the mysql table
         $sql = "UPDATE $table SET name='$name', email='$email', comments='$comments' WHERE ID='$id'";
          $insert = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
      
          print "&gb_status=The guestbook has been edited.&done=yes&";
          return;
       }
       print "&_root.write.gb_status=Error!&";
       break;
   case 'delete' :
        // Recieve Variables From Flash
       $submit = $_POST['submit'];
       $entryNum = $_POST['entryNum'];
          
       // 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 = "SELECT * FROM $table ORDER BY 'ID' DESC LIMIT " . $_GET['NumLow'] . ",1";
         $fewComments = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
          $id = mysql_result($fewComments, 0, 'ID');
          // Insert the data into the mysql table
         $sql = "DELETE FROM $table WHERE ID ='$id'";
          $insert = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
          print "&gb_status=Entry deleted.&done=yes&";
          return;
       }
       print "&_root.write.gb_status=Error!&";
       break;
  }
?>

Here's what I did:
I added two "actions" that the flash file can call to manipulate the database. One is 'edit' and the other is 'delete'. 'edit' simply updates a record and 'delete' deletes a record, obviously. I also turned the  $numComments variable into a value that is passed to the php script by flash (I did this because in the admin tool I only wanted to display 1 record at a time instead of 10).

You can make a simple administrator by making a copy of the gbv2.fla file, I called mine gbv2Admin. In the 'write' movie I added a new "delete" button and instead of the "submit" button calling the 'write' action I had it call the 'edit' action so that it will modify the entry that is displayed. Likewise the "delete" button calls the 'delete' action to delete the record that is displayed. The 'edit' and 'delete' actions, unlike the 'write' action, also require that you pass the NumLow variable so the script knows which record you're working with. so the ActionScript on the "Submit" button looks like:
on(click){
   /*
   Modify these reference paths to yours if you
   have changed them. Also modify gb_status
   reference path if required
   */
   yourname = _parent._parent.write.yourname.text;
   youremail = _parent._parent.write.youremail.text;
   yourcomments = _parent._parent.write.yourcomments.text;
   
   // Check variable data
   if (yourname eq "") {
      _parent._parent.write.gb_status.text = "Required: Name";
   } else if (youremail eq "") {
      _parent._parent.write.gb_status.text = "Required: Email Address";
   } else if (!youremail.length || youremail.indexOf("@") == -1 || youremail.indexOf(".") == -1) {
      _parent._parent.write.gb_status.text = "Required: Valid Email Address";
   } else if (yourcomments eq "") {
      _parent._parent.write.gb_status.text = "Required: Comments";
   } else {
      _parent._parent.write.gb_status.text = "Please wait...";
      newEntry = new LoadVars();
      newEntry.ref = this;
      newEntry.submit = "Yes";
      newEntry.yourname = yourname;
      newEntry.youremail = youremail;
      newEntry.yourcomments = yourcomments;
      newEntry.entryNum = Number(_parent._parent.read.low.text);
      newEntry.sendAndLoad("GuestBook.php?action=edit&numComments=1&r="+random(999)+"&NumLow="+_parent._parent.NumLow, newEntry, "POST");
      newEntry.onLoad = function(success){
         if(success){
            _parent._parent.write.gb_status.text = this.gb_status;
            _parent._parent.read.loadEntries("Default", 1);
            // Clear fields
            _parent._parent.write.yourname.text = "";
            _parent._parent.write.youremail.text = "";
            _parent._parent.write.yourcomments.text = "";
         }
      }
   }
}

I know this is brief so let me know if there are any questions.
Logged
Mohsin Sumar
Global Moderator
Systems Administrator
*****
Posts: 1646

Mohsin Sumar, Extreme Web Technologies

mohsinsumar@hotmail.com mohsinsumar
View Profile WWW Email
« Reply #1 on: 09/24/04, 04:03 »

Hi and Welcome to the Boards Jamie.
I'm glad to see somebody did this Smiley
I'll try this later on Smiley
Logged

- Best Regards, Mohsin Sumar
- Mohsin Sumar dot com is hosted by Extreme Web Technologies
rinser
Server what's that
*
Posts: 14


View Profile Email
« Reply #2 on: 09/06/05, 08:16 »

Hello.
let me see if i get this right, perhaps someone might be able to steer me in the general direction if they see my mistakes.
(i have already successfully installed the gbV2 and its working fine so far)
1. change the PHP script i am using to the one here

2.
Quote
You can make a simple administrator by making a copy of the gbv2.fla file, I called mine gbv2Admin
this means that, erm, i make another flash movie ? if so, i store it where ? how does it work ? does it work in tandem with my original flash movie ?

SORRY, im a beginner here. please let me know someone where i might go from here thanks a lot
-dj
Logged
Jamie SJ
Server what's that
*
Posts: 3



View Profile Email
« Reply #3 on: 09/07/05, 11:02 »

Hello.
let me see if i get this right, perhaps someone might be able to steer me in the general direction if they see my mistakes.
(i have already successfully installed the gbV2 and its working fine so far)
1. change the PHP script i am using to the one here

2.
Quote
You can make a simple administrator by making a copy of the gbv2.fla file, I called mine gbv2Admin
this means that, erm, i make another flash movie ? if so, i store it where ? how does it work ? does it work in tandem with my original flash movie ?

SORRY, im a beginner here. please let me know someone where i might go from here thanks a lot
-dj

It has been a long time since I posted that so let me se if I can recall what I did.

Yes the admin movie is a separate flash file. The way I set it up, the admin flash file should be in the same directory as the main gbv2.swf. The way the admin movie works is it manipulates the database the same way the main movie does. The difference is that it allows you to edit and delete entries. It doesn't communicate directly with the main flash movie.

hope that helps.

J
Logged
Jaxx
Server what's that
*
Posts: 1


View Profile Email
« Reply #4 on: 11/14/05, 07:30 »

Hi there. First of all,  only recently found this board on the web and must say:  I'm impressed.  quality floats I guess Smiley  Keep it up!

Regarding the admin version of the guestbook: sounds logical enough. Make a new version of guestbook.php is simple, but the adaptation of the new .fla-file isn't clear to me.  Pasting the supplied AS-code on the submit button,  so that it gets 'edit' functionality? OK.  But what about the delete functionality? Where is that supposed to come from?

Sorry to bother you with this,  but I'm stuck. Uhuh, designer, not programmer Wink Guestbook is working on http://www.vsdive.com. Feel free to tell me what you think.

PS:  do you know of an elegant way for Flashversion/player detection besides the js cript that is standard provided by Flash 8 publish function?
Logged
Jamie SJ
Server what's that
*
Posts: 3



View Profile Email
« Reply #5 on: 11/20/05, 21:13 »

Hi there. First of all,  only recently found this board on the web and must say:  I'm impressed.  quality floats I guess Smiley  Keep it up!

Regarding the admin version of the guestbook: sounds logical enough. Make a new version of guestbook.php is simple, but the adaptation of the new .fla-file isn't clear to me.  Pasting the supplied AS-code on the submit button,  so that it gets 'edit' functionality? OK.  But what about the delete functionality? Where is that supposed to come from?

Sorry to bother you with this,  but I'm stuck. Uhuh, designer, not programmer Wink Guestbook is working on http://www.vsdive.com. Feel free to tell me what you think.

PS:  do you know of an elegant way for Flashversion/player detection besides the js cript that is standard provided by Flash 8 publish function?

The design and implementation is up to you. Whether you create a "delete" and "edit" button or make new pages for each. From the codeing perspective, just pay attention to the following ActionScript code on the "Submit" button:
Code:
newEntry.sendAndLoad("GuestBook.php?action=edit&numComments=1&r="+random(999)+"&NumLow="+_parent._parent.NumLow, newEntry, "POST");

the "action" is what is important. In this case the "action=edit" but to create a delete button use "action=delete".

J
Logged
pirategirl
Server what's that
*
Posts: 1


View Profile
« Reply #6 on: 11/29/05, 20:45 »

Has anyone been able to get this to work? I am stumped  Huh

Are the variables for the record you want to delete or edit supposed to populate the fields of the "write" movie? How exactly is the admin supposed to work?

Seems like a step or two is missing (or my brain is not seeing something that is obvious to everyone else who is reading this thread). Any insight would be much appreciated. Smiley
Logged
mrmarlon
Server what's that
*
Posts: 2


View Profile Email
« Reply #7 on: 12/01/05, 12:44 »

Hi Jami S!!
I am a newbe web designer and I have been using a custom copy of guestbook v2 on my site
Could you be able to send me, for educational purpose the zip file containing the admin tools of the new guestbook v2
please
thank you marechavala@gmail.com
Logged
Temujin
Server what's that
*
Posts: 3


View Profile Email
« Reply #8 on: 10/03/06, 11:56 »

can you post ur gbv2Admin.fla file, Jamie ? I stll dont get the "edit" & "delete" thing in "Submit" button  Huh Cry
Logged
hornmartin
Server what's that
*
Posts: 4


View Profile
« Reply #9 on: 01/11/09, 17:47 »

Hi User,
who has the guestbook admin tools in a zip.
I think it has nowhere.
   
Can someone do for me?

Sorry, I only speak German and very little english!

Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #10 on: 01/12/09, 03:07 »

Hi everybody,
Admin for the guestbook is a little work, maily on the php side.
Flash itself has nearly nothing to do, but sending the commands.

If you did the loading and saving tutorials and have a basic understanding on how to handle database records with php, you can manage to extend the guestbook to whatever you like.

It is not meant to be a complet copy/paste application. It is a sample, to show how things work, and give you a direction on what is possible with little effort.

If you want to delete a record, you need to send the record index to a php script, which does a delete query against the database.
The same is for edit - you send the record to a script doing a update query.

Even if I sound boring: programming is not a cut and paste job - you have to have a vision of what you want to do, a basic plan how things work, and finaly write this in the code of the favored programming language.
Logged

happy flashing
Cool
Ronald
hornmartin
Server what's that
*
Posts: 4


View Profile
« Reply #11 on: 03/24/09, 14:18 »

Hello I have tried these instructions and it works somehow not!

Why can not the old Flash-db GuestBook version 2.0 in Flash GuestBook db version 2.1 with Admin Tools

thus would also be the case long ago it!

Please someone do it
Sprache erkennen
 
>
Englisch
 
vertauschen
Übersetzen
      
Logged
hornmartin
Server what's that
*
Posts: 4


View Profile
« Reply #12 on: 04/23/09, 15:20 »

For me it does not work there who can please make this Admintoolls
I wait long been forever!

Please I will not play another guestbook looking for!
Please help me!
 Angry Angry Angry Angry Huh Huh
Logged
hornmartin
Server what's that
*
Posts: 4


View Profile
« Reply #13 on: 05/02/09, 18:12 »

   
How long am I going to wait!  Embarrassed
Logged
arie_aj
Server what's that
*
Posts: 4


View Profile
« Reply #14 on: 07/23/10, 05:44 »

nice job jamie,,but at edit this file at .fla:

   yourname = _parent._parent.write.yourname.text;
   youremail = _parent._parent.write.youremail.text;
   yourcomments = _parent._parent.write.yourcomments.text;
   
   // Check variable data
   if (yourname eq "") {
      _parent._parent.write.gb_status.text = "Required: Name";
   } else if (youremail eq "") {
      _parent._parent.write.gb_status.text = "Required: Email Address";
   } else if (!youremail.length || youremail.indexOf("@") == -1 || youremail.indexOf(".") == -1) {
      _parent._parent.write.gb_status.text = "Required: Valid Email Address";
   } else if (yourcomments eq "") {
      _parent._parent.write.gb_status.text = "Required: Comments";
   }


at this my edit undefined.....
What's inside the file. fla that you have to edit??
Logged
Pages: [1] 2 Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!