ios - PHP MySQL request from Objective-C iPhone app not POST-ing to my table -
i'm trying make simple app posts data mysql server (wamp or mamp) @ home, when go our robotics competition in st. louis, able add scouting data teams database , pull later.
i'm having trouble getting data post table have set up.
here objective c code:
nsstring *myrequeststring = [nsstring stringwithformat:@"teamnumber=%@&matchnumber=%@&autogoal=%@&autoreachedow=%@&autocrosseddef=%@&teleopoffense=%@&teleopcrosseddef=%@&teleophighgoalsmissed=%@&teleophighgoalsmade=%@&teleoplowgoalsmissed=%@&teleoplowgoalsmade=%@&teleopendgame=%@&teleopdefense=%@&teleopshotsdef=%@&teleopshotsdisrupted=%@&teleoppenalties=%@", teamnumber, matchnumber, autogoal, autoreachedow, autocrosseddef, teleopoffense, teleopcrosseddef, teleophighgoalsmissed, teleophighgoalsmade, teleoplowgoalsmissed, teleoplowgoalsmade, teleopendgame, teleopdefense, teleopshotsdef, teleopshotsdisrupted, teleoppenalties]; nsdata *myrequestdata = [nsdata datawithbytes: [myrequeststring utf8string] length: [myrequeststring length]]; nsmutableurlrequest *request = [[nsmutableurlrequest alloc] initwithurl: [nsurl urlwithstring: @"http://localhost:8888/add.php"]]; // set request type [request sethttpmethod: @"post"]; // set content-type [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; // set request body [request sethttpbody: myrequestdata]; // send request , response nsdata *returndata = [nsurlconnection sendsynchronousrequest: request returningresponse: nil error: nil]; // log response nsstring *response = [[nsstring alloc] initwithbytes:[returndata bytes] length:[returndata length] encoding:nsutf8stringencoding]; nslog(@"%@",response);
here php code using make request iphone app:
<?php $servername = “localhost:8888”; $username = “root”; $password = “root”; $dbname = “teamdata”; $db_conn = new mysqli($servername, $username, $password, $dbname); if (!$conn) { die("connection failed: " . mysqli_connect_error()); echo "connection failed."; } $teamnumber = ($_post['teamnumber']); $matchnumber = ($_post['matchnumber']); $autogoal = ($_post['autogoal']); $autoreachedow = ($_post['autoreachedow']); $autocrosseddef = ($_post['autocrosseddef']); $teleopoffense = ($_post['teleopoffense']); $teleopcrosseddef = ($_post['teleopcrosseddef']); $teleophighgoalsmissed = ($_post['teleophighgoalsmissed']); $teleophighgoalsmade = ($_post['teleophighgoalsmade']); $teleoplowgoalsmissed = ($_post['teleoplowgoalsmissed']); $teleoplowgoalsmade = ($_post['teleoplowgoalsmade']); $teleopendgame = ($_post['teleopendgame']); $teleopdefense = ($_post['teleopdefense']); $teleopshotsdef = ($_post['teleopshotsdef']); $teleopshotsdisrupted = ($_post['teleopshotsdisrupted']); $teleoppenalties = ($_post['teleoppenalties']); $qry = 'insert appdata (`teamnumber`,`matchnumber`,`autogoal`,`autoreachedow`,`autocrosseddef`,`teleopoffense`,`teleopcrosseddef`, `teleophighgoalsmissed`, `teleophighgoalsmade`, `teleoplowgoalsmissed`, `teleoplowgoalsmade`, `teleopendgame`, `teleopdefense`, `teleopshotsdef`, `teleopshotsdisrupted`, `teleoppenalties`) values ($teamnumber,$matchnumber,$autogoal,$autoreachedow,$autocrosseddef,$teleopoffense,$teleopcrosseddef,$teleophighgoalsmissed,$teleophighgoalsmade,$teleoplowgoalsmissed,$teleoplowgoalsmade,$teleopendgame,$teleopdefense,$teleopshotsdef,$teleopshotsdisrupted,$teleoppenalties)'; if ($qry) { $message = "success"; } else { $message = "failed"; } echo utf8_encode($message); ?>
when run app , press save button (which runs objective c code), don't rows added table on local server.
i not getting nslog outputs.
if point me in right direction, please so. if need more info, let me know. monitoring few hours. thank you.
Comments
Post a Comment