Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: [help] mohon bantuan koreksi kesalahan script AS3 dan PHP for guestbook saya.

  1. #1
    kidchun is offline Anggota BabaFlash
    Join Date
    Apr 2011
    Location
    yogyakarta
    Posts
    13

    Default [help] mohon bantuan koreksi kesalahan script AS3 dan PHP for guestbook saya.

    master-master disini, mohon bantuan sekali, saya sudah bingung setengah mati, dah seminggu saya googling gk ada ketemu jalan keluarnya. saya punya masalah dalam pembuatan guestbook dengan flash dan php + sql. begini masalah saya. applikasi tersebut saya jalankan di local server wamp, dengan mozzila firefox4. saat aplikasi saya jalankan, tampilannya normal, keluhannya pada saat submit komentar, kotak komentar tidak menampilkan komentar yang telah dibuat. akan tetapi jika browser di reload, komenta baru tampil di kotak komentar. apa permasalahan dari aplikasi saya ini. disini saya sertakan script saya, mohon dengan sangat bantuannya. terima kasih sebelumnya.

    ini script AS3 buat SendEntries
    Code:
    msg_txt.restrict = "A-Za-z 0-9";
    name_txt.restrict = "A-Za-z 0-9";
    location_txt.restrict = "A-Za-z 0-9";
    // Set text formatting colors for errors, waiting..., and success mechanisms
    var errorsFormat:TextFormat = new TextFormat();
    errorsFormat.color = 0xFF0000;
    // hide the little processing movieclip
    processing_mc.visible = false;
    // Assign a variable name for our URLVariables object
    var variables:URLVariables = new URLVariables();
    //  Build the varSend variable
    var varSend:URLRequest = new URLRequest("guestbookParse.php");
    varSend.method = URLRequestMethod.POST;
    varSend.data = variables;
    // Build the varLoader variable
    var varLoader:URLLoader = new URLLoader;
    varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
    varLoader.addEventListener(Event.COMPLETE, completeHandler);
    // Handler for PHP script completion and return
    function completeHandler(event:Event):void{
        // remove processing movieclip
        processing_mc.visible = false;
        // Clear the form fields
        name_txt.text = "";
        location_txt.text = "";
        msg_txt.text = "";
        // Load the response from the PHP file
        status_txt.text = event.target.data.return_msg;
        gbOutput_txt.condenseWhite = true;
        gbOutput_txt.htmlText = "" + event.target.data.returnBody;
    }
    // Add an event listener for the submit button and what function to run
    submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
    // Validate form fields and send the variables when submit button is clicked
    function ValidateAndSend(event:MouseEvent):void{
       
        // validate all the form fields
        if(!name_txt.length) {   
            status_txt.text = "Please enter your name.";   
            status_txt.setTextFormat(errorsFormat);
        } else if(!location_txt.length) {
            status_txt.text = "Please enter your location";
            status_txt.setTextFormat(errorsFormat);
        }  else if(!msg_txt.length) {
            status_txt.text = "Please enter a message into the guestbook.";
            status_txt.setTextFormat(errorsFormat);
        } else {
            // All is good so send the message to the parse file
            // Show the little "processing_mc" movieclip
            processing_mc.visible = true;
            // Ready the variables for sending
            variables.comType = "parseComment";
              variables.userName = name_txt.text;
               variables.userLocation = location_txt.text;
               variables.userMsg = msg_txt.text;   
            // Send the data to the php file
               varLoader.load(varSend);
            // Put a temporary message in the response field while the PHP file sends back
            // If the code does not connect to the PHP file this message will remain visible to user
            status_txt.text = "Waiting for server connection...";
        } // close else after form validation
    
    } // Close ValidateAndSend function ////////////////////
    dan ini buat requestEntries :

    Code:
    // This section of code gets all the comments for initial viewing
    // Assign a variable name for our URLVariables object
    var variables_re:URLVariables = new URLVariables();
    //  Build the varSend variable
    var varSend_re:URLRequest = new URLRequest("guestbookParse.php");
    varSend_re.method = URLRequestMethod.POST;
    varSend_re.data = variables_re;
    // Build the varLoader variable
    var varLoader_re:URLLoader = new URLLoader;
    varLoader_re.dataFormat = URLLoaderDataFormat.VARIABLES;
    varLoader_re.addEventListener(Event.COMPLETE, completeHandler_re);
    // Handler for PHP script completion and return
    function completeHandler_re(event:Event):void{
        // Load the response from the PHP file
        if (event.target.data.returnBody == "") {
            gbOutput_txt.text = "No data coming through";
        } else {
            gbOutput_txt.condenseWhite = true;
            gbOutput_txt.htmlText = "" + event.target.data.returnBody;
        }
    }
    // Ready any variables for sending
    variables_re.comType = "requestEntries";
    // Send the data to the php file
    varLoader_re.load(varSend_re);

    ini PHP yang saya pake untuk koneksi database saya :

    Code:
    <?php
    /* 
    ::::::::::Script Written By: Adam Khoury @ w*w.developphp.c*m:::::::::::::
    :::::::::If you find w*w.developphp.c*m tutorials helpful or handy:::::::::::::
    ::::::::::Please link to it wherever possible to help others find it::::::::::::::::
    */
    //  IMPORTANT!!!! Connect to MySQL database here(put your connection data here)
    mysql_connect("localhost","root","") or die (mysql_error());
    mysql_select_db("kid") or die (mysql_error());
    
    if ($_POST['comType'] == "parseComment") {
    
        $name = $_POST['userName'];
    	$location = $_POST['userLocation'];
        $comment = $_POST['userMsg'];
        // 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);
        //$location = mysql_real_escape_string($location);
        //$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 guestbook (name, post_date, comment, location) 
            VALUES('$name', now(),'$comment','$location')")  
            or die (mysql_error());
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    	// Assemble body and send back to flash showing their new comment or entry
    	$body = "";
        $sql = mysql_query("SELECT * FROM guestbook ORDER BY post_date DESC"); 
        while($row = mysql_fetch_array($sql)) {
    		$id = $row["id"];
    		$name = $row["name"];
    		$post_date = $row["post_date"];
    		$comment = $row["comment"];
    		$location = $row["location"];
    		//$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);
    		$location = eregi_replace("'", "'",  $location);
    		$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));
    
    		$body .= '<u><b><font color="#790000">' . $name .  '</font>    |    <font color="#9B9B9B">' . $location .  '</font>      |      <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 $nameSent, thanks!&returnBody=$body";
         exit();
    
    } // close first if for post
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /* 
    ::::::::::Script Written By: Adam Khoury @ www.developphp.com:::::::::::::
    :::::::::If you find w*w.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 guestbook ORDER BY post_date DESC"); 
        while($row = mysql_fetch_array($sql)) { 
    		$id = $row["id"];
    		$name = $row["name"];
    		$post_date = $row["post_date"];
    		$comment = $row["comment"];
    		$location = $row["location"];
    		$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));
    
    		$body .= '<u><b><font color="#790000">' . $name .  '</font>    |    <font color="#9B9B9B">' . $location .  '</font>      |      <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
    ?>
    Mohon dengan sangat atas bantuannya.

  2. #2
    Blue_maniac7's Avatar
    Blue_maniac7 is offline BF Maniac
    Join Date
    Jun 2009
    Location
    Bandung
    Posts
    740

    Default

    Hmm... kalo gini gimana, untuk yang requestEntries :

    function completeHandler_re(event:Event):void{
    var variables2:URLVariables = new URLVariables( event.target.data );
    // Load the response from the PHP file
    if (variables2.returnBody == "") {
    gbOutput_txt.text = "No data coming through";
    } else {
    gbOutput_txt.condenseWhite = true;
    gbOutput_txt.htmlText = "" + variables2.returnBody
    ;
    }
    }
    Tapi gak tau juga yah. Karna saya blum nyobain scriptnya om .
    Last edited by Blue_maniac7; 04-30-2011 at 02:29 PM. Reason: var variables2:URLVariables = new URLVariables( e.target.data ); harusnya var variables2:URLVariables = new URLVariables(

  3. #3
    kidchun is offline Anggota BabaFlash
    Join Date
    Apr 2011
    Location
    yogyakarta
    Posts
    13

    Default

    maaf om sydah saya coba, tetapi malah nggak muncul sama sekali tampilannya.

  4. #4
    Blue_maniac7's Avatar
    Blue_maniac7 is offline BF Maniac
    Join Date
    Jun 2009
    Location
    Bandung
    Posts
    740

    Default

    Eh, maaf om. Tadi saya nulisnya
    var variables2:URLVariables = new URLVariables( e.target.data );
    harusnya
    var variables2:URLVariables = new URLVariables( event.target.data );

    kalo itu bisa gak?

  5. #5
    42Unregistered is offline Flash Geek
    Join Date
    Nov 2008
    Posts
    805

    Default

    Quote Originally Posted by kidchun View Post

    ini script AS3 buat SendEntries

    ....
    dan ini buat requestEntries :
    // This section of code gets all the comments for initial viewing
    // Assign a variable name for our URLVariables object
    var variables_re:URLVariables = new URLVariables();
    ....

    Mohon dengan sangat atas bantuannya.
    jika benar begitu urutan AS di Flashnya, maka coba buat yg requestEntries : di layer 1, dan SendEntries di layer ke-2.
    Sudah ada komentarnya:
    // This section of code gets all the comments for initial viewing

    Jadi semua komentar dipanggil dulu, baru insert komentar baru, terus dipanggil lagi...

  6. #6
    Blue_maniac7's Avatar
    Blue_maniac7 is offline BF Maniac
    Join Date
    Jun 2009
    Location
    Bandung
    Posts
    740

    Default

    Bukannya ngirim komentar terus komentarnya ditampilin yah om?

  7. #7
    42Unregistered is offline Flash Geek
    Join Date
    Nov 2008
    Posts
    805

    Default

    Quote Originally Posted by Blue_maniac7 View Post
    Bukannya ngirim komentar terus komentarnya ditampilin yah om?
    pastinya ngambil data dr database adalah yg pertama setelah itu baru insert

  8. #8
    42Unregistered is offline Flash Geek
    Join Date
    Nov 2008
    Posts
    805

  9. #9
    kidchun is offline Anggota BabaFlash
    Join Date
    Apr 2011
    Location
    yogyakarta
    Posts
    13

    Default

    Quote Originally Posted by Blue_maniac7 View Post
    Bukannya ngirim komentar terus komentarnya ditampilin yah om?
    betul betul om send and load., neh saya coba dulu ya semuanya, om master master pendahulu makasih banyak, ternyata forum babaflash sangat membantu, orangnya juga responsivable....maksih om om, salam kenal dari pemula ini...

  10. #10
    kidchun is offline Anggota BabaFlash
    Join Date
    Apr 2011
    Location
    yogyakarta
    Posts
    13

    Default

    Quote Originally Posted by 42Unregistered View Post
    om bagus banget guestbooknya om, bisa bimbing saya om, coz pake kode yang punya saya, gagal mulu, punya saya bisa nampilin komentar kalo dah di reload browsernya. masih kacau mpe sekarang..., ada tutor nya gk om, kalo ada mohon di review donk om.

Page 1 of 2 12 LastLast

Similar Threads

  1. animasi saya knp y??mohon bntuannya
    By k4z4m4 in forum Beginner
    Replies: 5
    Last Post: 07-11-2011, 09:19 AM
  2. mohon bantuan script
    By daywie in forum Beginner
    Replies: 1
    Last Post: 07-08-2010, 04:39 PM
  3. mohon tolongin saya
    By uburuber in forum Beginner
    Replies: 1
    Last Post: 04-26-2010, 04:48 PM
  4. mohon tolongin saya
    By uburuber in forum Open Source
    Replies: 1
    Last Post: 04-26-2010, 04:48 PM
  5. Tolong bantuin saya mohon
    By [L]a[R]c in forum Getting Started
    Replies: 1
    Last Post: 04-19-2010, 09:42 AM

Bookmarks

Posting Permissions

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