php - How to store data on data base in android studio with API 23? -
most of times don't post because can find need in others posts, 1 has me few days now, how guys store in databases? here java code
@override protected object doinbackground(object[] params) { try { url url = null; url = new url("http://www.myserver.com/register.php"); httpurlconnection conn = null; conn = (httpurlconnection) url.openconnection(); conn.setreadtimeout(connection_timeout); conn.setconnecttimeout(connection_timeout); conn.setrequestmethod("post"); conn.setdoinput(true); conn.setdooutput(true); dataoutputstream os = new dataoutputstream(conn.getoutputstream()); uri.builder builder = new uri.builder().appendqueryparameter("name", user.name) .appendqueryparameter("age", user.age + "") .appendqueryparameter("username", user.username) .appendqueryparameter("password", user.password); string query = builder.build().getencodedquery(); bufferedwriter writer = new bufferedwriter(new outputstreamwriter(os, "utf-8")); writer.write(query); writer.flush(); writer.close(); os.close(); } catch (malformedurlexception e) { e.printstacktrace(); } catch (protocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } return null; }
i tried lot of solutions nothing works, can't put in database. every time find help, outdated. here php file. thank you.
<?php $con = mysql_connect("hostname", "user", "passwd") or die (mysql_error()); mysql_select_db("database", $con) or die (mysql_error()); echo $name = $_post["name"]; echo $age = $_post["age"]; echo $username = $_post["username"]; echo $password = $_post["password"]; $sql_query = "insert userinfo values('', '$name','$age','$username','$password');"; $req = mysql_query($sql_query); ?>
i used mysqli didn't work tried mysql_ here was
$statement = mysqli_prepare($con, "insert userinfo (name, age, username, password) value (?, ?, ?, ?);"); mysqli_stmt_bind_param($statement, "siss", $name, $age, $username, $password); mysqli_stmt_execute($statement); mysqli_stmt_close($statement); mysqli_close($con);
i haven't "exeption" or "failed to" , don't inderstand are
e/surface﹕ getslotfrombufferlocked: unknown buffer: 0xab759330
there android manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="app_invaders.depaname" > <uses-permission android:name="android.permission.internet"/> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".login" android:label="@string/title_activity_login" > </activity> <activity android:name=".register" android:label="@string/title_activity_register" > </activity> </application> </manifest>
i guess, you're trying add id value in,
$sql_query = "insert userinfo values('', '$name','$age','$username','$password');";
instead of this. try using this,
$sql_query = "insert userinfo values('$name','$age','$username','$password')";
Comments
Post a Comment