Here's my code to connect my android studio in my database using these code and and it is running without an error.
TextView textView = findViewById(R.id.t1);
EditText sname = findViewById(R.id.et1);
EditText salary = findViewById(R.id.et2);
Button b1 = findViewById(R.id.b1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url = "http://127.0.0.1:80/New%20folder/new.php:name=" + sname.getText().toString() + "salary=" + salary.getText().toString();
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Handle error
}
});
}
});
}
}
My question is here in my PhP code
<?php
$mysqli = new mysqli("127.0.0.1","root","","try");
// Check connection
if ($mysqli -> connect_error) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
}
else
{
echo "dasds";
$s = $_GET['sname'];
$u = $_GET['salary'];
$res=mysql_query($con, "Insert into information (name,salary) values('$s','$u')");
}
$conn->close();
?>
Here's the error. How should I fix this?
Warning: Undefined array key "sname" in C:\xampp\htdocs\New folder\new.php on line 12
Warning: Undefined array key "salary" in C:\xampp\htdocs\New folder\new.php on line 13
Fatal error: Uncaught Error: Call to undefined function mysql_query() in C:\xampp\htdocs\New folder\new.php:15 Stack trace: #0 {main} thrown in C:\xampp\htdocs\New folder\new.php on line 15