2012-10-04 32 views
1

我的PHP代碼是windows phone7,我想通過使用PHP頁面發佈我的數據。

<?php 
    $id = $_GET['id']; 

    define("__ZBXE__", true); 
    include("../../files/config/db.config.php"); 
    $connect = @mysql_connect(localhost, kah601, kah909090); 
    @mysql_select_db("kah601", $connect); 
    @mysql_query("set names utf8"); 

$name = $_POST['name']; 
$name = $_POST['ox_score']; 
$name = $_POST['between_score']; 
$name = $_POST['order_score']; 
$name = $_POST['total_score']; 


$sql = sprintf("INSERT INTO `jp_mango` (`name`, `ox_score`, `between_score`, `order_score`, `total_score`) VALUES ('%s', '%s', '%s', '%s' , '%s');",$name, $ox_score, $between_score, $order_score, $total_score); 



$result = mysql_query($sql, $connect); 

mysql_close(); 

?> 

我要上傳5個數據(姓名,ox_score,between_score,order_score,total_score)。

我從堆棧溢出引用此代碼。 但我無法發佈數據。 當我看到加載頁面時,顯示爲這樣。 (數字自動遞增)

"num":"8","name":"","ox_score":"","between_score":"","order_score":"","total_score":"" 

我該如何發佈此類數據? 請幫我一把。

string sendData = ""; 
      Uri site = new Uri("http://kah601.cafe24.com/jp_mango_writeboard.php"); 
      WebClient wc = new WebClient(); 
      wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; 
      sendData += "name=hello"; 
      sendData += "ox_score=10"; 
      sendData += "between_score=10"; 
      sendData += "order_score=10"; 
      sendData += "total_score=30"; 
      wc.Headers[HttpRequestHeader.ContentLength] = sendData.Length.ToString(); 
      wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted); 
      //wc.UploadStringAsync(site, "POST", post_name, "name"); 
      wc.UploadStringAsync(site, "POST", sendData); 

回答

0

我,你有這樣的

"num":"8","name":"","ox_score":"","between_score":"","order_score":"","total_score":"" 

數據比你應該使用

$newdata=json_decode($_POST['data']); 

$name=$newdata->name; 
$ox_store=$newdara->ox_score; 
//and more... 
+0

omg愚蠢的錯誤..........非常感謝。 –

+0

@CindyKim你有解決方案嗎? – StaticVariable

+0

uhm。還沒。在第一次,我改變了我的PHP代碼。 $ name = $ _POST ['name']; $ ox_score = $ _POST ['ox_score']; ... 喜歡這個。但它只發布名稱。然後我改變了你的代碼。 ($ name = $ newdata-> name; $ ox_score = $ newdara-> ox_score; ...)但它沒有發表任何內容。我是一個PHP,WP7初學者。 : - <........ –

1

此外,你將不得不修改字符串格式這樣

sendData += "name=hello"; 
sendData += "&ox_score=10"; 
sendData += "&between_score=10"; 
sendData += "&order_score=10"; 
sendData += "&total_score=30"; 

即加'&'

+0

哦,它的工作原理!非常感謝!!! –

+0

你可以upvote答案,如果它幫助你,我認爲你是新來的Stackoverflow!還請接受@ jhonraymos的回答,因爲它解決了您的主要問題 – nkchandra

+0

哦,對不起。但我無法贊成。因爲我的聲譽只有1。我想我應該知道我怎樣才能提高我的聲譽。 –

相關問題