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
dan ini buat requestEntries :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 ////////////////////
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 :
Mohon dengan sangat atas bantuannya.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 ?>



LinkBack URL
About LinkBacks

Reply With Quote
.



Bookmarks