Most of the times I don't post anything because I can find everything I need in others posts, but this one has me for a few days now, how do you guys store anything in your databases? Here is my 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 a lot of solutions but nothing works, I can't put anything in the database. Every time I find something that could help, it is outdated. Here is the 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 into UserInfo values('', '$name','$age','$username','$password');";
$req = mysql_query($sql_query);
?>
I used mysqli but it didn't work so I tried with mysql_ here it was
$statement = mysqli_prepare($con, "INSERT INTO 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 any "exeption" or "failed to" just that and i don't inderstand what they are
E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xab759330
there is my 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>