Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Hosted PHP to: receive JSON, Parse, Send to MySQL
Post Flair (click to view more posts with a particular flair)
Post Body

Hello, I am currently working through completing a small project where my swift mobile app decodes and encodes jSON from a php script hosted on a web server. It is very flawed and really just needs to have bare functionality. I am completing for a school project and my group got left with nobody in the Dev speciality. So far a PHP script pulls the data from the mySQL database, and outputs it as JSON on this web server. The swift mobile app can then pull and parse this data from the URL and use it in some functions, then encode the new values back to JSON. The JSON is then ready to push to a URL. I have it outputting as a string as well so I can see the encoded JSON.

What I need to do from here is have a PHP script that I can host that can:

  1. Wait to receive a push with JSON data from the app

  2. Decode the data into a result array

  3. Take the data in this array and update the corresponding values in the database with it.

Here is the PHP that uploads it as JSON:

<?php

// Create connection

$con=mysqli_connect("db5006352648.hosting-data.io","DB Here","Password Here","dbs5290591");

// Check connection

if (mysqli_connect_errno())

{

echo "Failed to connect to MySQL: " . mysqli_connect_error();

}

// This SQL statement selects ALL from the table 'Locations.. will update'

$sql = "SELECT * FROM Users";

// Check if there are results

if ($result = mysqli_query($con, $sql))

{

// If so, then create a results array and a temporary one

// to hold the data

$resultArray = array();

$tempArray = array();

// Loop through each row in the result set

while($row = $result->fetch_object())

{

// Add each row into our results array

$tempArray = $row;

array_push($resultArray, $tempArray);

}

// Finally, encode the array to JSON and output the results

echo json_encode($resultArray);

}

// Close connections

mysqli_close($con);

?>

Here is is the output of the JSON in the app that is ready to be pushed:

//Encoded Json Output:
{"firstName":"Tommy","accessLevel":"1","lastName":"Bones","userIsAuthenticated":"1","BadgeScannerLong":"84.510","badgeScannerLat":"39.130"}

additionally the Hosted JSON that is pulled from the database and hosted can be seen at https://www.gatekeeperapp.org/service.php .

Thank you so much for any help or guidance you can provide. Anything will truly go a long way.

Author
Account Strength
80%
Account Age
4 years
Verified Email
Yes
Verified Flair
No
Total Karma
159
Link Karma
89
Comment Karma
70
Profile updated: 1 day ago
Posts updated: 1 month ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago