sql - Trouble posting to database, from iOS app -
i'm having problem updating database ios app...
sql statements
<?php // create connection $con=mysqli_connect("server_name","user_name","user_code","table_name"); // check connection if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } // sql statement selects table 'table.name' $sql = "select * table_name"; // check if there results if ($result = mysqli_query($con, $sql)) { // if so, create results array , temporary 1 // hold info $resultarray = array(); $temparray = array(); // loop through each row in result set while($row = $result->fetch_object()) { // add together each row our results array $temparray = $row; array_push($resultarray, $temparray); } // finally, encode array json , output results echo json_encode($resultarray); } $sql = "insert table_name (column_name) values('1')"; // close connections mysqli_close($result); mysqli_close($con); ?> my ios code
for (tickets *items in _feeditems){ if ([resulttext.text isequal:(id) items.ticketnumber]) { status.text = @"match found"; //contacting database------------------------------ nsstring *strurl = [nsstring stringwithformat:@"ticketdate=%@", items.ticketdate]; nsdata *postdata = [strurl datausingencoding:nsasciistringencoding allowlossyconversion:yes]; nsstring *postlength = [nsstring stringwithformat:@"%d",[postdata length]]; nsmutableurlrequest *request = [[nsmutableurlrequest alloc] init]; [request seturl:[nsurl urlwithstring:@"http://webservice.com"]]; [request sethttpmethod:@"post"]; [request setvalue:postlength forhttpheaderfield:@"content-length"]; [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"current- type"]; [request sethttpbody:postdata]; nsurlconnection *conn = [[nsurlconnection alloc]initwithrequest:request delegate:self]; if(conn) { nslog(@"connection successful"); } else { nslog(@"connection not made"); } //contacting database end------------------------------------------- break; }else { status.text = @"match not found"; } } i connection succesful nslog there nil getting updated in database.
i'm trying manually type in ticket number app, , if matches ticket in database (it works), want the ticketdate alter 0 1.
but not alter :/
you not calling
[conn start]; to have request sent. i.e.:
nsurlconnection *conn = [[nsurlconnection alloc]initwithrequest:request delegate:self]; [conn start]; you should aware request sent asynchronously, means not response right after calling start. should do, if want remain async connection, implement data delegate, , @ to the lowest degree – connection:didreceivedata:, – connectiondidfinishloading:, , connection:didfailloadingwitherror: methods.
alternatively, might consider sending request synchronously, i.e., replacing
nsurlconnection *conn = [[nsurlconnection alloc]initwithrequest:request delegate:self]; with:
[nsurlconnection sendsynchronousrequest:request returningresponse:nil error:nil]; but kind os request block app ui, unless send them on background thread.
ios sql json
No comments:
Post a Comment