mysql - iOS and PHP: Timeout error -
it has been 4 years since last wrote php code. trying write web service insert mysql database table. i'm passing data via post. in app using nsurlconnection , initing ok nsurlrequest. getting timeout error. when check db table it's cardinality still 0 know data not being inserted. , not getting hits on nsurlconnection delegate methods. suspicion there wrong php code. take @ , let me know if see odd.
i know url correct. know post data being attached request ok.
here's ios code:
- (bool) submitaccountdata : (nsarray*) arraccounttextfields { bool success = yes; //set url nsurl* accounturl = [nsurl urlwithstring:kaccountservice]; nsmutableurlrequest* accounturlrequest = [nsmutableurlrequest requestwithurl:accounturl]; nsmutabledictionary* dictpostdata = [[nsmutabledictionary alloc] init]; for(kip_textfield* thistextfield in arraccounttextfields) { nsstring* strkey = thistextfield.placeholder; strkey = [strkey stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]]; strkey = [strkey stringbyreplacingoccurrencesofstring:@" " withstring:@""]; if (thistextfield.mytextfieldtype == secure_textfield) { strkey = [strkey stringbyreplacingoccurrencesofstring:@"word" withstring:@""]; } [dictpostdata setvalue:thistextfield.text forkey:strkey]; } //add post data accounturlrequest = [self postdata:accounturlrequest :dictpostdata]; //uncomment below see post data being sent //nsstring* strpostdata = [nsstring stringwithutf8string:(char*)[[accounturlrequest httpbody] bytes]]; //nslog(@"%@", strpostdata); nsurlconnection* myurlconnection = [[nsurlconnection alloc] initwithrequest:accounturlrequest delegate:self]; if(myurlconnection) { [myurlconnection start]; } else { nslog(@"connection not made"); bool success = no; } return success; }
here's php code.
<?php //get passed variables $username = $_post['username']; $usercity = $_post['usercity']; $userstate = $_post['userstate']; $userstateabbrev = $_post['userstateabbrev']; $useremail = $_post['useremail']; $userpass = $_post['userpass']; //put array $arruserinfo = arrasy($username, $usercity, $userstate, $userstateabbrev, $useremail, $userpass); $servername = "ramjamlaxcom1.ipagemysql.com"; $username = "mpl_admin"; $password = "mpl_admin"; $dbname = "mpl_main"; // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) { echo "connection failed!"; die("connection failed: " . $conn->connect_error); } mysql_select_db(mpl_main); //create prepared statement $stmt = $dbh->prepare("insert accounts (username, usercity, userstate, userstateabbrev, useremail, userpass) values (:username, :usercity, :userstate, :userstateabbrev, :useremail, :userpass)"); $stmt->bindparam(':username', $username); $stmt->bindparam(':usercity', $usercity); $stmt->bindparam(':userstate', $userstate); $stmt->bindparam(':userstateabbrev', $userstateabbrev); $stmt->bindparam(':useremail', $useremail); $stmt->bindparam(':userpass', $userpass); $stmt->execute(); //check success if (mysql_affected_rows() > 0) { echo "success"; } else { echo "failed"; } ?>
Comments
Post a Comment