php - Log in ios app from user date in sql database -
im trying create application user must sign in.
<?php include ("./inc/connect.inc.php"); header('content-type: application/json'); if($_post) { $user = 'username'; $pass = 'password'; $sql = "select * player firstname='$user' , lastname='$pass'"; $usercount = mysql_num_rows($sql); //count number of rows returned if ($usercount == 1) { echo '{"success":1}'; } else { echo '{"success":0,"error_message":"username and/or password invalid."}'; } }else { echo '{"success":0,"error_message":"username and/or password invalid."}'; } ?>
if change if $usercount = 1 part if($_post['username'] == 'steffgriff' && $_post['password'] == 'password'). , entered in on application steffgriff , password work. ideas why wont work count function. i'll put below code in app also
- (ibaction)signinclicked:(id)sender { nsinteger success = 0; @try { if([[self.txtusername text] isequaltostring:@""] || [[self.txtpassword text] isequaltostring:@""] ) { [self alertstatus:@"please enter email , password" :@"sign in failed!" :0]; } else { nsstring *post =[[nsstring alloc] initwithformat:@"username=%@&password=%@",[self.txtusername text],[self.txtpassword text]]; nslog(@"postdata: %@",post); nsurl *url=[nsurl urlwithstring:@"http://www.rugbycoachanalysis.com/jsonlogin.php"]; nsdata *postdata = [post datausingencoding:nsasciistringencoding allowlossyconversion:yes]; nsstring *postlength = [nsstring stringwithformat:@"%lu", (unsigned long)[postdata length]]; nsmutableurlrequest *request = [[nsmutableurlrequest alloc] init]; [request seturl:url]; [request sethttpmethod:@"post"]; [request setvalue:postlength forhttpheaderfield:@"content-length"]; [request setvalue:@"application/json" forhttpheaderfield:@"accept"]; [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; [request sethttpbody:postdata]; //[nsurlrequest setallowsanyhttpscertificate:yes forhost:[url host]]; nserror *error = [[nserror alloc] init]; nshttpurlresponse *response = nil; nsdata *urldata=[nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error]; nslog(@"response code: %ld", (long)[response statuscode]); if ([response statuscode] >= 200 && [response statuscode] < 300) { nsstring *responsedata = [[nsstring alloc]initwithdata:urldata encoding:nsutf8stringencoding]; nslog(@"response ==> %@", responsedata); nserror *error = nil; nsdictionary *jsondata = [nsjsonserialization jsonobjectwithdata:urldata options:nsjsonreadingmutablecontainers error:&error]; success = [jsondata[@"success"] integervalue]; nslog(@"success: %ld",(long)success); if(success == 1) { nslog(@"login success"); } else { nsstring *error_msg = (nsstring *) jsondata[@"error_message"]; [self alertstatus:error_msg :@"sign in failed!" :0]; } } else { //if (error) nslog(@"error: %@", error); [self alertstatus:@"connection failed" :@"sign in failed!" :0]; } } } @catch (nsexception * e) { nslog(@"exception: %@", e); [self alertstatus:@"sign in failed." :@"error!" :0]; } if (success) { [self performseguewithidentifier:@"login_success" sender:self]; }
}
any ideas? thanks
instead of setting $user
, $pass
variables static strings, try retrieving them $_post
array, this:
if($_post) { $user = $_post['username']; $pass = $_post['password']; // rest of code
Comments
Post a Comment