java - Android response code 200 from php mysql but does not make entries in database -


i sending data android app form php mysql server , server getting response code 200 failed make entries database.

here php file sending post variables

    <?php  $host='localhost'; $uname='root'; $pass='pass'; $db='app';   $con=mysqli_connect($host,$uname,$pass,$db);   $first_name=$_post['first_name']; $last_name=$_post['last_name']; $phone=$_post['phone']; $mail_id=$_post['mail_id']; $password =$_post['password']; $la=$_post['la']; $lo=$_post['lo']; $ac=$_post['ac']; $pro=$_post['pro'];  if($con){  echo "connected database $first_name "; //print variable check file getting inputs.its working. } else{ echo 'failed connect database '; }   $sql="insert `mobile_app`(`first_name`, `last_name`, `phone`, `mail_id`, `password`, `la`, `lo`, `ac`, `pro`) values ($first_name,$last_name,$phone,$mail_id,$password,$la,$lo,$ac,$pro)";  if(mysqli_query($con,$sql)){ echo 'data inserted successfully'; } else{ echo "error: not able execute $sql.". mysqli_error($con) ; }  mysqli_close($con); ?> 

this java file

    public class sending_data_to_server extends asynctask{ string lo,la,ac,pro,first_name,last_name,phone,mail_id,password; bufferedreader reader;  @override protected string doinbackground(string... params) {     //variables     first_name=params[0];     last_name=params[1];     phone=params[2];     mail_id=params[3];     password=params[4];     lo=params[5];     la=params[6];     ac=params[7];     pro=params[8];     log.d("send data values",first_name+last_name+lo+la+phone);       try {         string data= urlencoder.encode("first_name","utf-8")+ "=" +urlencoder.encode(first_name,"utf-8");         data+= "&" +urlencoder.encode("last_name","utf-8")+ "=" +urlencoder.encode(last_name,"utf-8");         data+= "&" + urlencoder.encode("phone","utf-8")+ "=" +urlencoder.encode(phone,"utf-8");         data+= "&" + urlencoder.encode("mail_id","utf-8")+ "=" +urlencoder.encode(mail_id,"utf-8");         data+= "&" + urlencoder.encode("password","utf-8")+ "=" +urlencoder.encode(password,"utf-8");         data+= "&" + urlencoder.encode("la","utf-8")+ "=" +urlencoder.encode(la,"utf-8");         data+= "&" + urlencoder.encode("lo","utf-8")+ "=" +urlencoder.encode(lo,"utf-8");         data+= "&" + urlencoder.encode("ac","utf-8")+ "=" +urlencoder.encode(ac,"utf-8");         data+= "&" + urlencoder.encode("pro","utf-8")+ "=" +urlencoder.encode(pro,"utf-8");            url url=new url("test/android/data/data.php");   // can't post complete url due restriction new users          httpurlconnection connection= (httpurlconnection) url.openconnection();         connection.setrequestmethod("post");         connection.setdoinput(true);         connection.setdooutput(true);          //for post - begin         connection.setdooutput(true);         outputstream os=connection.getoutputstream();         bufferedwriter writer=new bufferedwriter(new outputstreamwriter(os,"utf-8"));         writer.write(data);         writer.flush();         writer.close();         os.close();         connection.connect();         //for post end         int responsecode=connection.getresponsecode();         log.d("sending class----","post response code "+responsecode);          if (responsecode==httpurlconnection.http_ok){             //success             reader=new bufferedreader(new inputstreamreader(connection.getinputstream()));             string inputline;             stringbuffer response=new stringbuffer();              while((inputline=reader.readline())!=null){                 response.append(inputline);             }             reader.close();              //print result             log.d("sending class----",response.tostring());          }         else{             log.d("sending class---","post did not work");          }       } catch (malformedurlexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     }       return "data submitted"; }  } 

here logcat

    06-29 20:48:52.703 7211-7211/com.boysjoys.com.pro_working1 d/registration class: ----all data ready , captured 06-29 20:48:52.723 7211-29559/com.boysjoys.com.pro_working1 d/send data values: helloworld28.531212977.25688999865321472 06-29 20:48:52.893 7211-7211/com.boysjoys.com.pro_working1 w/fragmentmanager: movetostate: fragment state appintrofragment{423d9470 #1 id=0x7f0e009f android:switcher:2131624095:1} not updated inline; expected state 3 found 2 06-29 20:48:52.933 7211-7211/com.boysjoys.com.pro_working1 d/appintrobasefragment: slide hello world has been selected. 06-29 20:48:53.423 7211-29559/com.boysjoys.com.pro_working1 d/sending class----: post response code 200 06-29 20:48:53.423 7211-29559/com.boysjoys.com.pro_working1 d/sending class----: connected database hello error: not able execute insert `mobile_app`(`first_name`, `last_name`, `phone`, `mail_id`, `password`, `la`, `lo`, `ac`, `pro`)values (hello,world,9810012345,google@gmail.com,adffgghhjjk,77.2568899,28.5312129,37.5,fixed).you have error in sql syntax; check manual corresponds mysql server version right syntax use near '@gmail.com,adffgghhjjk,77.2568899,28.5312129,37.5,fused)' @ line 2 

and database structure rows want insert app data

till have tried many tutorials , guide , of places have seen httpclient depreciated working httpurlconnection , server returned status code 200 think fault in php mysql file not sure.

as @adam forbis suggest print mysql error , check value getting php file.so did , edit php file details , m updating logcat mysql error

maybe try follow in you're php file (replace you're $sql var one):

$sql="     insert `mobile_app`     (         `first_name`,         `last_name`,         `phone`,         `mail_id`,         `password`,         `la`,         `lo`,         `ac`,         `pro`     )     values (         '".$first_name."',         '".$last_name."',         $phone,         '".$mail_id."',         '".$password."',         $la,         $lo,         $ac,         '".$pro."'     ) ;"; 

this same answer @ f_anto, confirm must have single quote arround you're strings. (i prefere write '".$var."' @ '$var')

this work me (similar code) testing you're problem :

<?php   $db = mysqli_connect("host", "userlogin", "userpwd", "dbname");  $id = 999; $idc = 1; $idd = 0; $p = "gpog@email.com"; $la = 15478.12; $l = 0;  $sql="         insert `table`         (             `field1`,             `field2`,             `field3`,             `field4`,             `field5`,             `field6`         )         values (             $id,             $idc,             $idd,             '".$p."',             $la,             $l         )     ;"; mysqli_query($db, $sql);  var_dump(mysqli_error($db)); 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -