$con = mysqli_connect("localhost", "root", "", "matgic");
$con = mysqli_connect("localhost", "root", "", "matgic");
$id_user = $_POST["id_user"];
$username = $_POST["username"];
$score = $_POST["score"];
$statement = mysqli_prepare($con, "UPDATE user SET score=? WHERE id_user = ? AND username =?");
mysqli_stmt_bind_param($statement, "isi",$id_user, $username,$score);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
$response = array();
$response["success"] = false;
while(mysqli_stmt_fetch($statement))
{
$response["success"] = true;
$response["user_id"] = $user_id;
$response["name"] = $name;
$response["username"] = $username;
$response["password"] = $password;
$response["date"] = $date;
$response["email"] = $email;
$response["score"] = $score;
}
echo json_encode($response);
public class ScoreRequest extends StringRequest {
public class ScoreRequest extends StringRequest
{
private static final String Score_Request_URL="http://192.168.1.221/Score.php";//declaramos una constante
private Map<String, String> params;
//constructor de la clase
public ScoreRequest (int id_user, String username, int score, Response.Listener<String> listener)
{
super(Request.Method.POST,Score_Request_URL,listener, null);
params= new HashMap<>();
params.put("id_user", id_user+"");
params.put("username", username);
params.put("score", score+"");
}//fin de constructor
@Override
public Map <String, String> getParams()
{
return params;
}//fin de método Map
}//fin de clase
}//fin de clase
btnno.setOnClickListener(new View.OnClickListener() {
btnno.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
int scoreaux;
scoreaux=Integer.parseInt(score);
scoreaux+=1;
final String usernameaux=username;
final int useraux=Integer.parseInt(userid);
Response.Listener<String> responseListener= new Response.Listener<String>()
{
@Override
public void onResponse(String response)
{
try
{
JSONObject jsonResponse=new JSONObject(response);
boolean success= jsonResponse.getBoolean("success");
if(success)
{
int user=jsonResponse.getInt("id_user");
String nameuser=jsonResponse.getString("username");
int scoreb=jsonResponse.getInt("score");
Intent intent=new Intent (Digits.this, Digits2.class);
intent.putExtra("id_user", user);
intent.putExtra("username", nameuser);
intent.putExtra("score", scoreb);
Digits.this.startActivity(intent);
}
else
{
AlertDialog.Builder builder=new AlertDialog.Builder(Digits.this);
builder.setMessage("User or Id incorrect")
.setNegativeButton("Retry", null)
.create().show();
}
}
catch (JSONException e)
{
e.printStackTrace();
}
}//fin de método onResponse
};//fin de Response.Listener<String>
ScoreRequest scoreRequest= new ScoreRequest(useraux,usernameaux,scoreaux, responseListener);
RequestQueue queue= Volley.newRequestQueue(Digits.this);
queue.add(scoreRequest);
}//fin de onclick
});//fin de setOnClickListener
//fin de método btnno
public class Digits2 extends AppCompatActivity { String username; int userid, score;
public class Digits2 extends AppCompatActivity
{
String username;
int userid, score;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_digits2);
Intent intent =getIntent();
score=intent.getIntExtra("score",-1);
username=intent.getStringExtra("username");
userid=intent.getIntExtra("id_user",-1);
}
}
}
Notice: Undefined index: id_user in C:\xampp\htdocs\Score.php on line 4
Notice: Undefined index: username in C:\xampp\htdocs\Score.php on line 5
Notice: Undefined index: score in C:\xampp\htdocs\Score.php on line 6 {"success":false}
Notice: Undefined index: id_user in C:\xampp\htdocs\Score.php on line 4
Notice: Undefined index: username in C:\xampp\htdocs\Score.php on line 5
Notice: Undefined index: score in C:\xampp\htdocs\Score.php on line 6 {"success":false}