-2

My current task now is propagating variables from script to script. Basically, I have coded a capability into my website to insert 4 variables into a database via a form get method.

Now, I have input coming from a Android app that posts information to my website using JSON. After decoding the JSON array and turning them into 4 variables, how do I take those four variables and propagate them to the same script that inserts them into the database?

Here is the code for the mobile php script server side.

<?php 
session_start();

$json = $_SERVER['HTTP_JSON'];

$data = json_decode($json);

$Latitude =  $data->Latitude;
$Longitude = $data->Longitude;
$Bldg = $data->Bldg;
$Room = $data->Room;

echo "Data Received. Thanks bruh!";
?>

And here is the script I want to send it to.

<?php
session_start();

$bld =$_POST["bld"];
$rnum =$_POST["rnum"];
$lat = $_POST["lati"];
$lon = $_POST["longi"];


//LOG ON AND ENTER INFORMATION INTO DATABASE
require_once('logconf.php');
try {
$dbh = new PDO($driver, $user, $pass, $attr);
} catch (Exception $e) {
echo 'Exception : ' . $e->getMessage() . "\n";
die();
}
.......
Cœur
  • 37,241
  • 25
  • 195
  • 267
maknelly
  • 131
  • 3
  • 12
  • Do you mean that the mobile application AND the script are separate Users? – clops Mar 14 '12 at 23:17
  • 3
    You should provide some code of what you are doing – Ibu Mar 14 '12 at 23:18
  • 2
    You could alternatively refactor the database insert into a separate procedure, then call from both the form and JSON files – James Holwell Mar 14 '12 at 23:21
  • I mean, since I already have that capability of posting to my database built in, can I use session or something to just receive the data from the phone in one script and then from that script post it to the other script that inserts it into the database? – maknelly Mar 14 '12 at 23:37

1 Answers1

0

first, why don't you join those two files?

second, you can use a function like this to send those data to your db script.

Community
  • 1
  • 1
Taha Paksu
  • 15,371
  • 2
  • 44
  • 78