简体   繁体   中英

Grabbing JSON from a activity and using it on a php page

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM