mysql - How to send database to server with HttpPost in Android and check -
i using code (which copied tutorial) send information database in mysql. in android app:
class uploadtodatabase extends asynctask<string, string, string> { list<namevaluepair> namevaluepairs= new arraylist<namevaluepair>(1); //metemos valores al database del server @override protected string doinbackground(string... params) { namevaluepairs.add(new basicnamevaluepair("_id", "2")); namevaluepairs.add(new basicnamevaluepair("columnname", params[0])); namevaluepairs.add(new basicnamevaluepair("columnimage", params[1])); namevaluepairs.add(new basicnamevaluepair("columnsound", "tercero")); try{ //jsonobject json = jsonparser.makehttprequest(url_create_product, // "post", params); httpclient httpclient= new defaulthttpclient(); httppost httppost= new httppost("http://192.168.1.35/androidfileupload/updata.php"); httppost.setentity(new urlencodedformentity(namevaluepairs)); httpresponse response= httpclient.execute(httppost); httpentity entity=response.getentity(); is=entity.getcontent(); //toast.maketext(getapplicationcontext(),"success",toast.length_long).show(); } catch(clientprotocolexception e) { log.e("clientprotocol","log_tag"); e.printstacktrace(); } catch(ioexception e){ log.e("log tag", "ioexception"); e.printstacktrace(); } catch(exception es){ log.e("fallo de excep", "ioexception"); es.printstacktrace(); } return null; }
and in wampserver use php code:
<? $dbhost = "localhost"; $dbuser = "xxxxx"; $dbpass = "xxxxx"; $dbname = "dbsound"; $table = "dbsound"; $conn = new mysqli_connect($dbhost,$dbuser,$dbpass,$dbname) if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $_id=$_post['_id']; $columnname=$_post['columnname']; $columnimage=$_post['columnimage']; $columnsound=$_post['columnsound']; mysqli_select_db("$dbname") or die("unable select database $dbname"); $sqlquery = "insert $table ("_id", "columnname", "$columnimage","columnsound") values(null,'$columnname','$columnimage','$columnsound')"; $results = mysqli_query($sqlquery); if ($conn->query($sqlquery) === true) { echo "new record created successfully"; } else { echo "error: " . $sqlquery . "<br>" . $conn->error; } $conn->close(); ?>
where in dbuser , dbpass put data of mysql. don't have error, doesn't appear in database, how can know if data sent?
Comments
Post a Comment