2016-12-10 37 views
1

我在Android Studio上有一個活動,從JSON獲取信息(來自index.php),現在我想在新的php頁面上使用這些信息,所以我可以在新查詢中使用它,將新值插入到phpmyadmin中。從活動中抓取JSON並在php頁面上使用它

下面是從的index.php

<?PHP 

include_once("connection.php"); 

if(isset($_POST['txtEmail']) && isset($_POST['txtPassword'])){ 

$email = $_POST['txtEmail']; 
$password = $_POST['txtPassword']; 
$query = "SELECT * FROM tbl_user WHERE email = '$email' 
    AND password = '$password'"; 

$result = mysqli_query($conn, $query); 

if($result->num_rows > 0){ //has record. correct username and password 

while($row[] = $result->fetch_assoc()) 
    { 

    $json = json_encode($row); 
    echo $json; 
    } 

    } else { 
     echo "0 results"; 
     exit; 
    } 

exit; 

} 
?> 
代碼

至極將顯示JSON,我要的是在另一個PHP頁面使用JSON的一個字段(例如ID返回)在一個新的查詢例如在WHERE語句中。

要使用在Android Studio中的JSON和活動之間移動它,我做了以下內容:

JSONArray jArray = new JSONArray(s); 
JSONObject json_data=null; 
json_data = jArray.getJSONObject(0); 
ct_name = json_data.getString("name"); 
ct_address = json_data.getString("address"); 
ct_email = json_data.getString("email"); 
ct_phone = json_data.getString("phone"); 


Bundle b = new Bundle(); 
b.putString("userdata",json_data.toString()); 
intent.putExtras(b); 
startActivity(intent); 

另一個想法,我不得不爲,如果我能搶ID(場的數據庫),第一php頁面(Index.php),然後在第二個頁面上使用它,所以它知道當時用戶是否登錄。我嘗試使用Sessions來做到這一點,但沒有運氣。也許是因爲PHP頁面不直接與eachother互動?

回答

0

Phpmyadmin是MySQL的前端。你的意思是你想要將你的數據插入MySQL數據庫表嗎?如果是這樣,您將需要擁有數據庫名稱以及用戶名和密碼。那麼你將不得不使用mysqli或PDO與數據庫進行交互。

+0

是的,這正是我的意思。事情是我使用它與Android Studio工作 – user3336801

+0

在這種情況下,看看這個,看看它是否有幫助:http://www.w3schools.com/php/php_mysql_insert.asp –