Welcome, Guest. Please login or register.
Did you miss your activation email?
02/07/12, 07:39
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)
| | |-+  Flash Guestbook . . . Please Help!
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: Flash Guestbook . . . Please Help!  (Read 2893 times)
James A T
Server what's that
*
Posts: 5


View Profile Email
« on: 03/24/06, 03:45 »

Dear Users,

My name is James Trickey (this is my first post here - what a nice forum). I need some help with the php coding etc as I can't seem to get to to work. When I launch the flash file (http://www.gloscheck.co.uk/gbv2.swf), it says 'undefined'.

This is the ID for the MySQL database:

gcheck_tutorials   
Users in tutorials
gcheck_root (Privileges: ALL PRIVILEGES)

Connection Strings
Perl $dbh = DBI->connect("DBI:mysql:gcheck_tutorials:localhost","gcheck_root","<PASSWORD HERE>");
PHP $dbh=mysql_connect ("localhost", "gcheck_root", "<PASSWORD HERE>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("gcheck_tutorials");

I have set up the table in the database and I can verify that PHP is installed.

Here is the PHP code I am using.

<?
/*
-----
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:       Comments 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 = "gcheck_root";            // Database User
  $DBpass = "";            // Database Pass
  $DBName = "gcheck_tutorials";            // Database Name
  $table = "guestbook";             // Database Table
  $numComments = $_GET['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'];
           
       // 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;
  }
?>

When I run the PHP script (on this URL: http://www.gloscheck.co.uk/GuestBook.php?action=read&NumLow=0), the following error comes up: Error in GuestBook Application:

"You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1"

I have no idea what to do next as I am new to this type of coding! Could someone please help me as I would be very grateful!

Cheers,
James.
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #1 on: 03/24/06, 03:51 »

Look for ` symbol in the $sql variable, ie:

SELECT * FROM `' . $table . '`

Delete them, since phpMyAdmin use it, some setups doesn't like it

Jorge
Logged

James A T
Server what's that
*
Posts: 5


View Profile Email
« Reply #2 on: 03/24/06, 03:53 »

Thanks very much - i'll try it and tell you the results  Wink I forgot to say that I am using CPanel.
Logged
James A T
Server what's that
*
Posts: 5


View Profile Email
« Reply #3 on: 03/24/06, 09:05 »

Thanks again for your help!

I have got it all up and running apart from one problem - the first entries display on page 2 (entries 10-20) which means you have to press the submit button just as it is loading to view any entries. Please can someone help! Here is the code I am using:

<?
/*
-----
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:       Comments 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 = "gcheck_root";            // Database User
  $DBpass = "";            // Database Pass
  $DBName = "gcheck_tutorials";            // Database Name
  $table = "guestbook";             // Database Table
  $numComments = $_GET[''];       // 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 = "James Trickey";
         $MyEmail = "info@gloscheck.co.uk";
          $Subject = "$name has just signed your guestbook.";
         $EmailBody = "Hello James,\n$name has just signed Gloscheck's guestbook available at http://www.gloscheck.co.uk. 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.gloscheck.co.uk\n~~~~~~~~~~~~~~~\nThanking you,\nJames Trickey";
       
          $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'] . "";
         $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;
  }
?>

Cheers,
James.  Roll Eyes
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #4 on: 03/24/06, 09:15 »

Check if the database have the entries, and please, don't repost the code over and over

Jorge
Logged

James A T
Server what's that
*
Posts: 5


View Profile Email
« Reply #5 on: 03/24/06, 13:15 »

Sorry for reposting the code I just wanted to show the (few) changes I had made. The database has the entries - the guestbook just wont display them on the first page, but other than that, everything is fine! I've got the entries you made here (by clicking the next button before it disappears) and from the MySQL database:

Name: jorge
Email: horge@test.com
Comments: test
Date: 2006-03-24 15:14:09

Name: jorge
Email: jorge@test.com
Comments: Just a second test
Date: 2006-03-24 15:13:23

Thanks,
James.
Logged
James A T
Server what's that
*
Posts: 5


View Profile Email
« Reply #6 on: 03/24/06, 14:08 »

Thanks for all your help - it's sorted now! The two rogue strings were the '$_GET[''];' and the '`'s

Cheers,
James.
Logged
arie_aj
Server what's that
*
Posts: 4


View Profile
« Reply #7 on: 07/23/10, 14:46 »

 $entryNum = $_POST['entryNum'];

 Roll Eyes Huh Huh
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6161


View Profile WWW Email
« Reply #8 on: 07/24/10, 01:27 »

what are you trying to say?
Logged

happy flashing
Cool
Ronald
Pages: [1] 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!