Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. <?php
  2. $servername = "";
  3. $user_n = "";
  4. $p_word = "";
  5. $dbname = "";
  6.  
  7. // Create connection
  8. $con = mysqli_connect($servername, $user_n, $p_word, $dbname);
  9.  
  10. // Check connection
  11. if (mysqli_connect_errno())
  12. {echo nl2br("Failed to connect to MySQL:".mysqli_connect_error()."n ");}
  13. else
  14. { echo nl2br("Established Database Connection n");}
  15.  
  16. $sanemail = mysqli_real_escape_string($con,$_POST['email']);
  17. $sanfname= mysqli_real_escape_string($con,$_POST['firstName']);
  18.  
  19.  
  20. //insert query to insert from data into the capstone table
  21. $sql = "UPDATE user_info SET fname = '$sanfirstName' WHERE email='$sanemail'"
  22.  
  23. //check for error on insert
  24. if (!mysqli_query($con,$sql))
  25. { die('Error:' .mysqli_error($con));}
  26.  
  27. echo "1 record added";
  28. mysqli_close($con);
  29. ?>
  30.  
  31. import UIKit
  32.  
  33. class userInformation: UIViewController {
  34. let URL_SAVE_TEAM = ""
  35.  
  36. // these three just added ----> you may need to add them down the line
  37. @IBOutlet weak var email: UITextField!
  38. @IBOutlet weak var password: UITextField!
  39. @IBOutlet weak var repeatPassword: UITextField!
  40. @IBOutlet weak var firstName: UITextField!
  41. @IBOutlet weak var lastName: UITextField!
  42. @IBOutlet weak var phoneNumber: UITextField!
  43. @IBOutlet weak var organization: UITextField!
  44. @IBOutlet weak var job: UITextField!
  45. @IBOutlet weak var website: UITextField!
  46. @IBOutlet weak var phoneNumberTwo: UITextField!
  47. @IBOutlet weak var emailNumberTwo: UITextField!
  48.  
  49. @IBAction func saveButtonTapped(_ sender: AnyObject) {
  50. //created NSURL
  51. let requestURL = NSURL(string: URL_SAVE_TEAM)
  52.  
  53. //creating NSMutableURLRequest
  54. let request = NSMutableURLRequest(url: requestURL! as URL)
  55.  
  56. //setting the method to post
  57. request.httpMethod = "POST"
  58.  
  59. //getting values from text fields
  60. let email = self.email.text
  61. let password = self.password.text
  62. let firstName = self.firstName.text
  63. let lastName = self.lastName.text
  64. let phoneNumber = self.phoneNumber.text
  65. let organization = self.organization.text
  66. let job = self.job.text
  67. let website = self.website.text
  68. let phoneNumberTwo = self.phoneNumberTwo.text
  69. let emailNumberTwo = self.emailNumberTwo.text
  70.  
  71. //Display Alert Messages
  72. func displayAlertMessage(userMessage:String)
  73. {
  74. let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.alert);
  75.  
  76. let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler:nil)
  77.  
  78. myAlert.addAction(okAction);
  79.  
  80. self.present(myAlert, animated: true, completion:nil)
  81. }
  82.  
  83. //If all the required fields are not filled out create an error message to the user
  84.  
  85. if(firstName!.isEmpty || lastName!.isEmpty)
  86. {
  87. displayAlertMessage(userMessage: "All fields are required fields to fill in")
  88. return
  89. }
  90.  
  91. //creating the post parameter by concatenating the keys and values from text field
  92. let postParameters = "email="+email!+"&password="+password!+"&firstName="+firstName!+"&lastName="+lastName!+"&phoneNumber="+phoneNumber!+"&organization="+organization!+"&job="+job!+"&website="+website!+"&phoneNumberTwo="+phoneNumberTwo!+"&emailNumberTwo="+emailNumberTwo!;
  93.  
  94. //adding the parameters to request body
  95. request.httpBody = postParameters.data(using: String.Encoding.utf8)
  96. let task = URLSession.shared.dataTask(with: request as URLRequest){
  97. data, response, error in
  98.  
  99. if error != nil{
  100. print("error is (error)")
  101. return;
  102. }
  103. //parsing the response
  104. do {
  105. //converting resonse to NSDictionary
  106. let myJSON = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary
  107.  
  108. //parsing the json
  109. if let parseJSON = myJSON {
  110.  
  111. //creating a string
  112. var msg : String!
  113.  
  114. //getting the json response
  115. msg = parseJSON["message"] as! String?
  116.  
  117. //printing the response
  118. print(msg)
  119.  
  120. }
  121. } catch {
  122. print(error)
  123. }
  124.  
  125. }
  126. //executing the task
  127. task.resume()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement