dqrqp8492 2016-12-10 18:18
浏览 60

从活动中抓取JSON并在php页面上使用它

I have a activity on Android Studio, grabbing information from JSON (that came from index.php), now I want to use this information on a new php page, so I can use it on a new query, to insert new values into phpmyadmin.

Here's the code from 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;

}
?>

Wich will display the JSON, what I want is to use one of the JSON fields (for example the ID returned) in a new query in another php page, for example in the WHERE statement.

To use the JSON on Android Studio and move it between activities I do the following:

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);

Another idea that I had was if I could grab the ID (field on the database), on the first php page (Index.php) and then use it on the second one, so it knows wich user is logged in at that time. I tried using Sessions to do this, but with no luck. Maybe because the php pages don't interact with eachother directly?

  • 写回答

1条回答 默认 最新

  • doujilou3903 2016-12-10 18:22
    关注

    Phpmyadmin is a front end for MySQL. Do you mean you want to insert your data into a MySQL database table? If so, you will need to have a database name as well as a username and password. Then you will have to use mysqli or PDO to interact with the database.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog