2012-05-15 57 views
0

我有一個變量名爲:name和一個名爲score的變量。從閃存傳遞變量到PHP和MySQL

我想在發佈時將它們發送到本地主機上的數據庫,以便我可以在頁面上顯示它們。我怎樣才能發送這兩個變量,並將它們添加到MySQL數據庫?

我使用的動作腳本2.0

謝謝

回答

0

您可以通過從Flash參數通過在URL中使用GET參數到PHP。

首先在Flash中製作URL,如http://www.your-site.org/page.php?name=John&age=21

然後訪問你在PHP中GET參數,如$name = $_GET["name"]; $age = $_GET["age"];

+0

如果你的網址中有一些奇怪的字符,你可能會遇到很多麻煩。 – jadkik94

+0

修正了這個問題。您也可以使用POST方法。它在很大程度上取決於您傳輸的數據。 –

+0

同意。只是爲了讓OP清楚,萬一他會遇到一些麻煩(空格,特殊字符......)。 – jadkik94

1

從ActionScript 2,您需要使用LoadVars

your_btn.onRelease = function() { 
    lv = new LoadVars(); 
    lv.score = score; 
    lv.name = name; 
    lv.load("http://localhost/send.php", "POST"); 
    lv.onLoad = function(src:String) { 
     if (src) { 
      // OK. src contains the output of the PHP file. 
      // i.e. what you "print" or "echo" from php. 
      trace(src); 
     } else { 
      // Problem. Most probably there's an error if src is undefined. 
     } 
    }; 
}; 

從PHP,你可以從$_POST陣列得到他們,並將其添加使用mysqli到MySQL。

$score = $_POST['score']; 
$name = $_POST['name']; 

// See a tutorial on how to add them to database. 
// You need to connect to MySQL, then do an INSERT query to your table. 

Mysqli Docs,或者搜索關於MySQL和php的一些教程,其中有很多。