简体   繁体   中英

Send form entries to a database

So basically I created a quick form in my storyboard, it contains date of birth with a UIDatePicker, address, phone number, etc. and I need that information to go to an SQLdatabase where I can retrieve that info and deliver my product how do I go about this? I am using swift and am relatively new to development, step-by-step isn't necessary but some specifics would be nice.

you can check these tutorial:

  1. An Example SQLite based iOS 8 Application using Swift and FMDB:

http://www.techotopia.com/index.php/An_Example_SQLite_based_iOS_8_Application_using_Swift_and_FMDB

  1. How to Use SQLite to Manage Data in iOS Apps: http://www.appcoda.com/sqlite-database-ios-app-tutorial/

Here's are some nice tutorials you could read through, but basically if you have a uibutton on the action of the button you can retrieve the information on the text fields, and you could have a NSObject class with all the Db information and just make the post or get request to a specific restapi

http://sourcefreeze.com/uitextfield-and-uitextfield-delegate-in-swift/

http://ios-blog.co.uk/tutorials/swift-how-to-send-a-post-request-to-a-php-script/

You can send data in via Third-Party API simple and clean or use NSURLSession , little harder cause this is basically you sending HTTP request manually.

Alamofire is a great example of Third-Party API and a lot of swift developers use it.

Example with Alamofire:

Create a Parameter of data you want to send:

let myParameters = [
    "date": variable ,
    "Name": variable ,
]

Send request: this is sending to PHP and php file will handle the database, you can use other server side scripting language.

Alamofire.request(.POST, "http://example.com/formData.php", paramters: myParameters)
         .responseJSON { response in
             debugPrint(response)
         }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM