www.webdeveloper.com
Results 1 to 4 of 4

Thread: PHP / mySQL / AS3 guestbook

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    Switzerland
    Posts
    1,101

    PHP / mySQL / AS3 guestbook

    Hi!
    I've been learning flash as3 lately, and I want to redo my website in flash, using the same db, so that they can both be viewed by the users.
    I found a cool tutorial on the web for a PHP/mySQL/AS3 guestbook, but I can't get the display to work. Actually, the values don't even get added to the db table (I used my existing guestbook table, called guestbookn, with a little more than 100 entries, so it's not empty).

    The php script is as follow : (I modified it a little for my needs, but the original version didn't work either . I could get the values inserted into the DB, but no display)

    PHP Code:
    <?
    // here the DB connection parameters (not very interesting, and I know the file DOES connect to the DB, so the problem doesn't come from here)
    $connection = mysql_connect("$hostname" , "$user" , "$pass");
    mysql_select_db($dbase , $connection) or die (mysql_error());

    if ($_POST['comType'] == "parseComment") {

        $name = $_POST['user_name'];
        $email = $_POST['user_email'];
        $sitename = $_POST['user_siteName'];
        $siteurl = $_POST['user_siteURL'];
        $comment = $_POST['user_message'];
        // Filter user input a little bit further using PHP if you allow more characters than I do in the Flash input text field
        $name = mysql_real_escape_string($name);
        $email = mysql_real_escape_string($email);
        $sitename = mysql_real_escape_string($sitename);
        $siteurl = mysql_real_escape_string($siteurl);
        $post = mysql_real_escape_string($comment);
        // uncomment this line below to preserve line breaks, paragraphs and such in the comment text
        $post = nl2br(htmlspecialchars($comment));
        // Add to DB
        $sql = mysql_query("INSERT INTO guestbookn (name, email, sitename, siteurl, date, comments) 
            VALUES('$name', '$email', '$sitename', '$siteurl', now(),'$comment')")  
            or die (mysql_error());
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Assemble body and send back to flash showing their new comment or entry
        $body = "";
        $sql = mysql_query("SELECT * FROM guestbookn ORDER BY post_date DESC"); 
        while($row = mysql_fetch_array($sql)) {
            $id = $row["id"];
            $name = $row["name"];
            $email = $row["email"]
            $post_date = $row["date"];
            $comment = $row["comments"];
            $sitename = $row["sitename"];
            $siteurl = $row["siteurl"];
            $n_post_body = str_replace("<br />", "", $n_post_body); // Use in case you get too many line breaks when preserving breaks
            $comment = stripslashes($comment);
            $name = eregi_replace("'", "'",  $name);
            $email = eregi_replace("'", "'",  $email);
            $sitename = eregi_replace("'", "'",  $sitename);
            $siteurl = eregi_replace("'", "'",  $siteurl);
            $comment = eregi_replace("'", "'", $comment);
            // Decode HTML entities if storing comments that preserve line breaks and such
            $n_post_body = html_entity_decode($n_post_body); // Uncomment to use
            $post_date = strftime("%b %d, %y", strtotime($post_date));

                
                if (  ($siteurl == '' AND $sitename == '') )
                {
        $body .= '<u><b><font color="#790000">' . $name . '</font>   |   <font color="#9B9B9B">' . $post_date . '</font></b></u>
            <br />
            '.$comment.'
            <br />
            <br />
            ';
                }
                
                elseif ( $siteurl == '' AND $sitename != '' )
                {
        $body .= '<u><b><font color="#790000">' . $name . '</font>   |    <font color="#9B9B9B">' . $sitename . '</font>     |     <font color="#9B9B9B">' . $post_date . '</font></b></u>
            <br />
            '.$comment.'
            <br />
            <br />
            ';
                }
                
                elseif ( ($siteurl != '' AND $sitename == '')  )
                {
        $body .= '<u><b><font color="#790000">' . $name . '</font>    |    <a href="'. $siteurl.'" target="_blank"><font color="#9B9B9B">' . $siturl . '</font></a>      |      <font color="#9B9B9B">' . $post_date . '</font></b></u>
            <br />
            '.$comment.'
            <br />
            <br />
            ';        
                }
                else 
                {
                    
        $body .= '<u><b><font color="#790000">' . $name . '</font>    |    <a href="'. $siteurl.'" target="_blank"><font color="#9B9B9B">' . $sitename . '</font></a>      |      <font color="#9B9B9B">' . $post_date . '</font></b></u>
            <br />
            '.$comment.'
            <br />
            <br />
            ';
                }

        
            }
        mysql_free_result($sql);
        mysql_close();
         
         // Echo into flash
         echo "return_msg=Entry has been added successfully $name, thanks!&returnBody=$body";
         exit();

    } // close first if for post
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /* 
    ::::::::::Script Written By: Adam Khoury @ www.developphp.com:::::::::::::
    :::::::::If you find www.developphp.com tutorials helpful or handy:::::::::::::
    :::::::::::please link to it wherever possible to help others find it::::::::::::::::
    */
    // Second part of the script is below, it simply requests all entries for initial display of the guestbook entries
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    if ($_POST['comType'] == "requestEntries") {

        $body = "";
        $sql = mysql_query("SELECT * FROM guestbookn ORDER BY post_date DESC"); 
        while($row = mysql_fetch_array($sql)) { 
            $id = $row["id"];
            $name = $row["name"];
            $email = $row["email"];
            $sitename = $row["sitename"];
            $siteurl = $row["siteurl"];
            $post_date = $row["date"];
            $comment = $row["comments"];
            $comment = stripslashes($comment);
            // Decode HTML entities if storing comments that preserve line breaks and such
            $n_post_body = html_entity_decode($n_post_body); // Uncomment to use
            $post_date = strftime("%b %d, %y", strtotime($post_date));

                if (  ($siteurl == '' AND $sitename == '') )
                {
        $body .= '<u><b><font color="#790000">' . $name . '</font>   |   <font color="#9B9B9B">' . $post_date . '</font></b></u>
            <br />
            '.$comment.'
            <br />
            <br />
            ';
                }
                
                elseif ( $siteurl == '' AND $sitename != '' )
                {
        $body .= '<u><b><font color="#790000">' . $name . '</font>   |    <font color="#9B9B9B">' . $sitename . '</font>     |     <font color="#9B9B9B">' . $post_date . '</font></b></u>
            <br />
            '.$comment.'
            <br />
            <br />
            ';
                }
                
                elseif ( ($siteurl != '' AND $sitename == '')  )
                {
        $body .= '<u><b><font color="#790000">' . $name . '</font>    |    <a href="'. $siteurl.'" target="_blank"><font color="#9B9B9B">' . $siturl . '</font></a>      |      <font color="#9B9B9B">' . $post_date . '</font></b></u>
            <br />
            '.$comment.'
            <br />
            <br />
            ';        
                }
                else 
                {
                    
        $body .= '<u><b><font color="#790000">' . $name . '</font>    |    <a href="'. $siteurl.'" target="_blank"><font color="#9B9B9B">' . $sitename . '</font></a>      |      <font color="#9B9B9B">' . $post_date . '</font></b></u>
            <br />
            '.$comment.'
            <br />
            <br />
            ';
                }

        
        }
        mysql_free_result($sql);
        mysql_close();
        echo "returnBody=$body";
        exit();
    } // close first if for post
    ?>
    My AS3 in my flash file :

    The sending data to php part :
    PHP Code:
    msg_txt.restrict="^*#<>/";
    name_txt.restrict="^*#<>/";
    email_txt.restrict="^*#<>/";
    siteName_txt.restrict="^*#<>/";
    siteURL_txt.restrict="^*#<>";

    // textformat pour les erreurs et les messages d'alerte
    var errorsFormat:TextFormat=new TextFormat();
    errorsFormat.color=0x0000FF;

    // cacher le processing
    processing_mc.visible=false;


    // assigner un nom de variables pour l'URLVariable.
    var variables:URLVariables=new URLVariables();
    // varSend variable
    var varSend:URLRequest=new URLRequest("guestbookParsemoi.php");
    varSend.method=URLRequestMethod.POST;
    varSend.data=variables;

    // varLoader
    var varLoader:URLLoader=new URLLoader();
    varLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
    varLoader.addEventListener(Event.COMPLETEcompleteHandler);

    // handler
    function completeHandler(event:Event):void {
        
    processing_mc.visible=false;
        
    // clear textfields
        
    msg_txt.restrict="";
        
    name_txt.restrict="";
        
    email_txt.restrict="";
        
    siteName_txt.restrict="";
        
    siteURL_txt.restrict="";
        
        
    // charger la réponse du php
        
    status_txt.text=event.target.data.return_msg;
        
    gbOutput_txt.condenseWhite=true;
        
    gbOutput_txt.htmlText="" event.target.data.returnBody;
    }

    // event listener sur le bouton submit :

    submit_btn.addEventListener(MouseEvent.MOUSE_DOWNValidateAndSend);

    // fonction de validation et d'envoi :
    function ValidateAndSend(event:MouseEvent):void {
        
    // validate form fields :
        
    if (!name_txt.length) {
            
    status_txt.text="Veuillez inscrire votre nom.";
            
    status_txt.setTextFormat(errorsFormat);
        }
        else if (!
    email_txt.length) {
        
    status_txt.text="Veuillez inscrire votre email (il ne sera pas publié).";
        
    status_txt.setTextFormat(errorsFormat);
        }
        else if (!
    msg_txt.length) {
            
    status_txt.text="Veuillez écrire un message.";
            
    status_txt.setTextFormat(errorsFormat);
        }
        else {
            
    // tout est bon, donc on envoie :
            
    processing_mc.visible=true;
            
    // préparer les variables pour l'envoi :
            
    variables.comType="parseComment";
            
    variables.user_name=name_txt.text;
            
    variables.user_siteURL=siteURL_txt.text;
            
    variables.user_siteName=siteName_txt.text;
            
    variables.user_email=email_txt.text;
            
    variables.user_message=msg_txt.text;
            
    // envoyer les données au php :
            
    varLoader.load(varSend);
            
    // un message pour dire qu'il est en train de faire la connexion :
            
    status_txt.text="En attente de la connexion au serveur.";
        }


  2. #2
    Join Date
    Aug 2004
    Location
    Switzerland
    Posts
    1,101
    The retrieving the data from php part :
    PHP Code:
    // déclaration des variables
    var variables_re:URLVariables= new URLVariables();

    // varSend variable
    var varSend_re:URLRequest= new URLRequest("guestbookParsemoi.php");
    varSend_re.method=URLRequestMethod.POST;
    varSend_re.data=variables_re;

    // varLoad variable
    var varLoader_re:URLLoader= new URLLoader;
    varLoader_re.dataFormat=URLLoaderDataFormat.VARIABLES;
    varLoader_re.addEventListener(Event.COMPLETEcompleteHandler_re);

    // handler pour le php script

    function completeHandler_re(event:Event):void {
        
    // réponse du php
        
    if (event.target.data.returnBody=="") {
            
    gbOutput_txt.text="aucune donnée";
        }
        else {
            
    gbOutput_txt.condenseWhite=true;
            
    gbOutput_txt.htmlText=""+event.target.data.returnBody;
        }
    }

    // préparer les variables pour l'envoi
    variables_re.comType="requestEntries";

    // envoyer les données au php
    varLoader_re.load(varSend_re); 
    My textfields in flash are :
    name_txt
    email_txt
    siteName_txt
    siteURL_txt
    msg_txt

    and the textfield which is supposed to display the guestbook entries :
    gbOutput_txt

    I could really use some help here, I've been looking at this code and trying stuff since Saturday

    Thanks !

  3. #3
    Join Date
    Aug 2004
    Location
    Switzerland
    Posts
    1,101

  4. #4
    Join Date
    Dec 2011
    Posts
    1

    Only want to bring about


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10632 seconds
  • Memory Usage 3,074KB
  • Queries Executed 13 (?)
More Information
Template Usage (30):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (27):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./includes/functions_threadedmode.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • bbcode_parse_start
  • postbit_imicons
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates