Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. func sendData() {
  2.  
  3. let postDataURL = "http://exampleip.com/Send.php"
  4. let url: NSURL = NSURL(string: postDataURL)!
  5. let request: NSMutableURLRequest = NSMutableURLRequest(url:url as URL)
  6.  
  7. let bodyData = String(1)
  8.  
  9. request.httpMethod = "POST"
  10. request.httpBody = bodyData.data(using: String.Encoding.utf8)
  11. NSURLConnection.sendAsynchronousRequest(request as URLRequest, queue: OperationQueue.main)
  12. {
  13. (response, data, error) in
  14. print(response!)
  15.  
  16. if let httpResponse = response as? HTTPURLResponse {
  17. let statusCode = httpResponse.statusCode
  18.  
  19. if statusCode==200 {
  20. print("Connection Successful")
  21.  
  22. } else {
  23. print("Connection Failed (!200)")
  24. }
  25. }
  26. }
  27. }
  28.  
  29. <?php
  30.  
  31. $host = "host";
  32. $db = "db";
  33. $user = "user";
  34. $pass = "pass";
  35.  
  36. $connection = mysql_connect($host,$user,$pass);
  37.  
  38. // Guessing: Posting into MySQL Object
  39. $id = $_POST["id"];
  40.  
  41. // Checking if connection can be established
  42. if(!$connection){
  43. die("Connection Failed");
  44. }
  45. else
  46. {
  47. // Selecting Database
  48. $dbconnect = mysql_select_db($db, $connection);
  49.  
  50. // Check if it can connect to Database
  51. if(!$dbconnect){
  52. die("Unable to connect to Database");
  53. }
  54. else
  55. {
  56. $query = sprintf("UPDATE tests SET testPop=testPop+1 WHERE id = %d", $id);
  57.  
  58. $resultset = mysql_query($query, $connection);
  59.  
  60. echo "Successfully added";
  61. echo $query;
  62. }
  63. }
  64.  
  65. ?>
  66.  
  67. CREATE TABLE IF NOT EXISTS `tests` (
  68. `id` int(11) NOT NULL AUTO_INCREMENT,
  69. `testName` varchar(255) DEFAULT NULL,
  70. `testPop` int(11) DEFAULT NULL,
  71. PRIMARY KEY (`id`)
  72. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ;
  73.  
  74. INSERT INTO `tests` (`id`, `testName`, `testPop`) VALUES
  75. (1, 'Test 1', '0'),
  76. (2, 'Test 2', '0'),
  77. (3, 'Test 3', '0'),
  78. (4, 'Test 4', '0'),
  79. (5, 'Test 5', '0'),
  80. (6, 'Test 6', '0'),
  81. (7, 'Test 7', '0'),
  82. (8, 'Test 8', '0'),
  83. (9, 'Test 9', '0'),
  84. (10, 'Test 10', '0'),
  85. (11, 'Test 11', '0'),
  86. (12, 'Test 12', '0');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement