SWiSHzone.com Support Forums Home

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Write To Guestbook From Database
Rednekheaven
post Nov 22 2009, 07:52 AM
Post #1


Advanced Member
***

Group: Members
Posts: 56
Joined: 7-September 09
Member No.: 61035



I have been asking around on the net and have been trying to figure out why the info a person enters in my guestbook doesnt show up in the entries area and also the totalEntries dont show up either. I have 2 movie clips one called write and one read. The write works fine everything is sent to my database, but dont send info back to the guestbook. Here is the code on the READ movie clip;

READ Movie Clip;

CODE
function loadEntries(act, increment) {
    
    // Define NumLow as a Number
    num = new Number(NumLow);
  
    // Act accordingly
    if(act == "Next") {
        
        // Add increment
        NumLow = num + increment;
    } else if(act == "Previous") {
        NumLow = num - increment;
    } else {
        
        // Load default - i.e. 0
        NumLow = 0;
    }
    
    // Update Statistics
        NumLow = NumLow;
        NumHigh = Number(NumLow) + 20;
    
    // Show Please wait text
    entries = "Loading entries... Please wait...";
    
    // Begin Loading
    myEntries = new LoadVars()
    myEntries.ref = this
    myEntries.load("GuestBook.php?action=read&r="+random(999)+"&NumLow="+NumLow)
    myEntries.onLoad = function(success){
        if(success){
          
          // Assign output to components and objects
            entries = this.entries;
            totalEntries = this.totalEntries;
      
            
             loadEntries("Default", 20);

    stop();
        }
    }
}



Where the entries/info is to appear its VAR = entries
Where the totalEntries are to appear its VAR - totalEntries


Now here is the php code;


CODE
// Part One - Initiate a mySQL Database Connection
// Database Connectivity Variables and other Variables
   $DBhost = "server";   // Database Server
   $DBuser = "user name";            // Database User
   $DBpass = "(******)";            // Database Pass
   $DBName = "my dbname";            // Database Name
   $table = "table name";             // Database Table
   $numComments = 20;       // 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');
                           $website = mysql_result($fewComments, $i, 'website');
                           $state = mysql_result($fewComments, $i, 'state');
               $comments = mysql_result($fewComments, $i, 'comments');
               $time = mysql_result($fewComments, $i, 'time');
              
            print '<b>Name: </b>' . $name . '<br><b>Email: </b>' . $email . '<br><b>Website: </b>' . $website . '<br><b>State: </b>' . $state . '<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']);
                 $website = ereg_replace("&", "%26", $_POST['yourwebsite']);
                 $state = ereg_replace("&", "%26", $_POST['yourstate']);
         $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`,
                                                                   `website`,
                                                                   `state`,
                   `comments`,
                   `time`
                  )
                  VALUES
                  (\'\','
                   . '\'' . $name . '\','
                   . '\'' . $email . '\','
                                                                   . '\'' . $website . '\','
                                                                   . '\'' . $state . '\','
                   . '\'' . $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 = "Name";
         $MyEmail = "Email";
         $Subject = "$name has just signed your guestbook.";
         $EmailBody = "Hello "",\n$name has just signed your guestbook available at http://your domian. 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://your domain\n~~~~~~~~~~~~~~~\nThanking you,\n"";
        
         $Message = $EmailBody.$EmailFooter;
        
         mail($MyName." <".$MyEmail.">",$Subject, $Message, "From: ".$name." <".$email.">");
         --> Remove this line */
        
         // Email Script End
        
        print "&error= &done=yes&";
         return;
         }
         print "&error=Error!&";
         break;
   }
?>



Only problem I am having is getting the entries and totalEntries to post. If someone could look over this and let me know what possibly could be wrong. Have tried all kinds of different things and no worky.



Thanks Kevin
Go to the top of the page
 
+Quote Post
bdg
post Nov 22 2009, 10:51 AM
Post #2


Advanced Member
***

Group: Members
Posts: 170
Joined: 30-December 05
From: USA
Member No.: 25116



Does your database return any results if you dont use flash but go directly to your page?
Go to the top of the page
 
+Quote Post
Rednekheaven
post Nov 22 2009, 02:15 PM
Post #3


Advanced Member
***

Group: Members
Posts: 56
Joined: 7-September 09
Member No.: 61035



QUOTE (bdg @ Nov 21 2009, 07:51 PM) *
Does your database return any results if you dont use flash but go directly to your page?



Dont know because my guestbook is made in flash-(swishmax2). So to find out would I have to make a guestbook on my page not in flash?
Go to the top of the page
 
+Quote Post
bdg
post Nov 22 2009, 05:00 PM
Post #4


Advanced Member
***

Group: Members
Posts: 170
Joined: 30-December 05
From: USA
Member No.: 25116



Load the php page directly in your browser,
your complete url and then GuestBook.php?action=read&NumLow=10
Do you get any results?
Go to the top of the page
 
+Quote Post
Rednekheaven
post Nov 22 2009, 11:58 PM
Post #5


Advanced Member
***

Group: Members
Posts: 56
Joined: 7-September 09
Member No.: 61035



Ok when I do that i get a blank white page with ---------

&_root.read.totalEntries=2&
&_root.read.entries=No More Entries!&


Here is the url to the guestbook, site not fully done made guestbook index while working on guestbook;
www.redneckheaven.net

Then you can see what you get

Thanks ------ Kevin
Go to the top of the page
 
+Quote Post
bdg
post Nov 23 2009, 07:30 AM
Post #6


Advanced Member
***

Group: Members
Posts: 170
Joined: 30-December 05
From: USA
Member No.: 25116



CAn you post the swi
Hard to tell from just this.
Your db is working though, there is a limit in the sql querry so by just putting in an arbitrary # directly in the url prevented it from displaying the entries.
The numLow value needs to be lower than the # of DB entries you have
If you set it to 0 it will display all.

Go to the top of the page
 
+Quote Post
Rednekheaven
post Nov 23 2009, 08:19 AM
Post #7


Advanced Member
***

Group: Members
Posts: 56
Joined: 7-September 09
Member No.: 61035



Here is the swi file:
Attached File(s)
Attached File  RNGuestbook.swi ( 866.59K ) Number of downloads: 5
 
Go to the top of the page
 
+Quote Post
bdg
post Nov 23 2009, 09:51 AM
Post #8


Advanced Member
***

Group: Members
Posts: 170
Joined: 30-December 05
From: USA
Member No.: 25116



Try making these changes to your read

change
CODE
// Define NumLow as a Number
    num = new Number(NumLow);

To
CODE
// Define NumLow as a Number
    num = new Number(this.NumLow);


change
CODE
myEntries.load("GuestBook.php?action=read&r="+random(999)+"&NumLow="+NumLow)

to
CODE
this.loadVariables("GuestBook.php?action=read&r="+random(999)+"&NumLow="+NumLow,'GET');


Change
CODE
// Assign output to components and objects
            entries = this.entries;
            totalEntries = this.totalEntries;
      
            
             loadEntries("Default", 20);

to
CODE
// Assign output to components and objects
            this.entries = entries;
            this.totalEntries =totalEntries;
      
            
             this.loadEntries("Default", 20);


see if that helps
Go to the top of the page
 
+Quote Post
Rednekheaven
post Nov 23 2009, 10:36 AM
Post #9


Advanced Member
***

Group: Members
Posts: 56
Joined: 7-September 09
Member No.: 61035



QUOTE (bdg @ Nov 22 2009, 06:51 PM) *
Try making these changes to your read

change
CODE
// Define NumLow as a Number
    num = new Number(NumLow);

To
CODE
// Define NumLow as a Number
    num = new Number(this.NumLow);


change
CODE
myEntries.load("GuestBook.php?action=read&r="+random(999)+"&NumLow="+NumLow)

to
CODE
this.loadVariables("GuestBook.php?action=read&r="+random(999)+"&NumLow="+NumLow,'GET');


Change
CODE
// Assign output to components and objects
            entries = this.entries;
            totalEntries = this.totalEntries;
      
            
             loadEntries("Default", 20);

to
CODE
// Assign output to components and objects
            this.entries = entries;
            this.totalEntries =totalEntries;
      
            
             this.loadEntries("Default", 20);


see if that helps



That worked, except only have to figure out why it shows up like this in the Guestbook;

<b>Name:</b>Kevin<br><b>Email:</b> ee.aol.com<b> ETC


Also when I go to the guestbook it doesnt show the entries or how many until I post a new one.
To make Name Email Wesite, etc on its own line do I need to put some in the php for that to happen?

This post has been edited by Rednekheaven: Nov 23 2009, 10:38 AM
Go to the top of the page
 
+Quote Post
bdg
post Nov 23 2009, 11:52 AM
Post #10


Advanced Member
***

Group: Members
Posts: 170
Joined: 30-December 05
From: USA
Member No.: 25116



in the text properties panel of the area holding the text to be displayed
click the render text as html button
then your text will be formatted.

The info wont be displayed since it doesnt call the php script until the send button is pushed.
php is all serside scripting so it needs something to be sent to it so it can run the code on the server.

Go to the top of the page
 
+Quote Post
Rednekheaven
post Nov 23 2009, 12:15 PM
Post #11


Advanced Member
***

Group: Members
Posts: 56
Joined: 7-September 09
Member No.: 61035



Ok got the entries to show properly. Thank You

So Is there somewhere or a way to have the entries and total entries to show onLoad? Would I have to say something like onLoad(Guestbook.php--etc) Not great at php learning as I go.

I really do appreicate your help.

Kevin
Go to the top of the page
 
+Quote Post
Rednekheaven
post Nov 23 2009, 12:42 PM
Post #12


Advanced Member
***

Group: Members
Posts: 56
Joined: 7-September 09
Member No.: 61035



Sorry for being such a PAIN in A**, another thing if just found out when I get more then 20 entries and go to next 20 it doesnt show any entries. and then try to go back and veiw previous entries it doesnt show them. Man i didnt know it was this complicated. I know one thing after getting this done firued out it sure will help alot with learning. To me see the code and what it does I learn faster then reading a book.
Go to the top of the page
 
+Quote Post
bdg
post Nov 25 2009, 08:58 AM
Post #13


Advanced Member
***

Group: Members
Posts: 170
Joined: 30-December 05
From: USA
Member No.: 25116



Yes, you can add it on the scene to load when the movie loads
(Use the same concept as how you got the entries, just use the total number of records returned as the variable)

Id have to look into the setup to see about the 20 records. Havent had time to look into that though.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 9th February 2010 - 10:53 PM