I want to get the name of the current logged in user and send it to php ..
I tried to type a name and it worked perfectly.
But if I want to send a variable like in here It doesn't work:
//let defaultValues = UserDefaults.standard
//let username1 = defaultValues.string(forKey: "username");
//let username2 = NSFullUserName()
let username2 = NSUserName()
let urlPath: String =
"http://127.0.0.1/PhpstormProjects/myiosapp/v1/MyWishes.php?username=username2" // here is the problem
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("Failed to download data")
}else {
print("Data downloaded")
self.parseJSON(data!)
}
}
task.resume()
}
...
I think it's because it sends the variable as a string.
This is the line of code in php (works good when sending a string):
$username = $_GET['username'];
$sql = "SELECT * FROM ITEM WHERE username = $username";
Any suggestions?