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.
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:
Wait to receive a push with JSON data from the app
Decode the data into a result array
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.
Subreddit
Post Details
- Posted
- 2 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/PHPhelp/com...