I currently have the following PHP script with a select query with all hard-coded values. How can I take the value provided by my Swift app?
Is there a way to easily edit the following code I have to have also POST a value instead of having a hard-coded value in the PHP script?
    // Create connection
$con=mysqli_connect("localhost”,”username”,”password”,”dbName”);
// Check connection
if (mysqli_connect_errno())
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// This SQL statement selects ALL from the table 'Equipment'
$sql = "SELECT name FROM TABLE 
        WHERE name = ‘$CHANGE THIS’ ";
// Check if there are results
if ($result = mysqli_query($con, $sql))
{
    // Create temporary connection
    $resultArray = array();
    $tempArray = array();
    // Look through each row
    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);
}
mysqli_close($con);
My current code in Swift looks like this:
The data I take from the SQL query is then put in an array and formatted in a UITable:
import Foundation
protocol FeedDetailProtocol: class {
    func itemsDownloaded(items: NSArray)
}
class FeedDetail: NSObject, URLSessionDataDelegate {
    weak var delegate: FeedDetailProtocol!
    let urlPath = "https://www.example.com/test/test1.php"
    func downloadItems() {
        let url: URL = URL(string: urlPath)!
        let defaultSession = Foundation.URLSession(configuration: URLSessionConfiguration.default)
        let task = defaultSession.dataTask(with: url) { (data, response, error) in
            if error != nil {
                print("Error")
            }else {
                print("details downloaded")
                self.parseJSON(data!)
            }
        }
        task.resume()
    }
    func parseJSON(_ data:Data) {
        var jsonResult = NSArray()
        do{
            jsonResult = try JSONSerialization.jsonObject(with: data, options:JSONSerialization.ReadingOptions.allowFragments) as! NSArray
        } catch let error as NSError {
            print(error)
        }
        var jsonElement = NSDictionary()
        let stocks = NSMutableArray()
        for i in 0 ..< jsonResult.count
        {
            jsonElement = jsonResult[i] as! NSDictionary
            let stock = DetailModel()
            //the following insures none of the JsonElement values are nil through optional binding
            if let name = jsonElement["name"] as? String,
            {
                print(name)
                stock.name = name
            }
            stocks.add(stock)
        }
        DispatchQueue.main.async(execute: { () -> Void in
            self.delegate.itemsDownloaded(items: stocks)
        })
    }
    }
