I am writing code for login and register application. Below is the android code & php script for register. The values are not storing in mysql database table (my_table).
When i open "http://fooddoof.freevar.com/Register.php" in brower i am getting the "Parse error: syntax error, unexpected '$username' (T_VARIABLE) in /home/vhosts/fooddoof.freevar.com/Register.php on line 8" error.
Android Java Script:
public class StoreUserDataAsyncTask extends AsyncTask<Void,Void,Void> {
User user;
GetUserCallback userCallback;
public StoreUserDataAsyncTask(User user,GetUserCallback userCallback){
this.user=user;
this.userCallback=userCallback;
}
@Override
protected Void doInBackground(Void... params) {
ContentValues contentValues=new ContentValues();
contentValues.put("username",user.username);
contentValues.put("password",user.password);
contentValues.put("email",user.email);
try {
URL url = new URL(SERVER_ADDRESS + "Register.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setReadTimeout(CONNECTION_TIMEOUT);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream out = conn.getOutputStream();;
BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(out,"UTF-8"));
writer.write(String.valueOf(params));
writer.flush();
writer.close();
out.close();
} catch (java.io.IOException e) {
e.printStackTrace();
}
return null;
}
PHP script:
<?php
$con=mysqli_connect("localhost","862322","varna123","862322")
$username = $_POST["username"];
$password = $_POST["password"];
$email= $_POST["email"];
$statement = mysqli_prepare($con, "INSERT INTO my_table (username, password, email) VALUES (?, ?, ?)");
mysqli_stmt_bind_param($statement, "sss",$username, $password, $email);
mysqli_stmt_execute($statement);
mysqli_stmt_close($statement);
mysqli_close($con); ?>
Please help if there is any wrong with this code.