I want to be able to connect my swift project to my database (hosted on blue host using phpmyadmin) and when the button is clicked, I want the value on the slider or label (since they are connected) to be inputed into a table in my database. I know this is a two part question but I am having a hard time finding a helpful resource for:
- connecting swift 3 to my database using php and phpmyadmin (I can't find a solid tutorial that explains where to put files and how to access them)
and
- how to send that value to the database.
I will be adding more to this but to break some ground on my project i really need a solid start with the connection and figuring out how to send data and retrieve it with swift and the database.
I really appreciate any help on this subject or even links to any resources that may help me. I am new to programming so all this is foreign to me.
// So far this is my code in [view controller.swift]
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var lbl: UILabel!
@IBAction func slider(_ sender: UISlider)
{
lbl.text = String(Int(sender.value))
}
func postToServerFunction() {
print(lbl.text!)
}
@IBAction func postToServerButton(_ sender: UIButton) {
postToServerFunction()
}
override func viewDidLoad()
{
super.viewDidLoad()
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
}
}
This is kind of a big subject so it would be hard to answer it in one fell swoop but seeing as nobody else has tried, let me try to help you out a little here.
I see you already have a function 'postToServerButton', which I'm assuming is connected to the 'Button' button in your storyboard. This is calling the postToServerFunction(), which I don't see written. I'll start out by writing that. You'll also need to connect the slider as an IBOutlet to your code to get its value. I'm writing this code from memory so some of it is probably wrong but hopefully you'll get the idea
So this next function is where things get complicated. This is connecting your code to a database. I've written some basic code below but this is a complex topic that depends on a variety of variables.
Check out this site for a good guide: http://www.ios-blog.co.uk/tutorials/swift/swift-how-to-send-a-post-request-to-a-php-script/