Я хочу обновить таблицу с помощью модернизации, поэтому у меня есть API следующим образом:
public interface StRegAPI {
@FormUrlEncoded
@POST("/stdreg.php")
public void regStudent(
@Field("stdid") String stdid,
@Field("stdpass") String stdpass,
@Field("stdadd") String stdadd,
@Field("stdphn") String stdphn,
@Field("stdemail") String stdemail,
Callback<Response> callback);
}
, где моя реализация обратного вызова -
StRegAPI api = adapter.create(StRegAPI.class);
//Defining the method insertuser of our interface
api.regStudent(
//Passing the values by getting it from editTexts
rn_list.getSelectedItem().toString(),
etstpass.getText().toString(),
etstad.getText().toString(),
etstphn.getText().toString(),
etstemail.getText().toString(),
//Creating an anonymous callback
new Callback<Response>() {
@Override
public void success(retrofit.client.Response result, retrofit.client.Response response) {
//On success we will read the server's output using bufferedreader
//Creating a bufferedreader object
BufferedReader reader = null;
//An string to store output from the server
String output = "";
try {
//Initializing buffered reader
reader = new BufferedReader(new InputStreamReader(result.getBody().in()));
//Reading the output in the string
output = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
//Displaying the output as a toast
Toast.makeText(StudReg.this, output, Toast.LENGTH_LONG).show();
}
@Override
public void failure(RetrofitError error) {
//If any error occured displaying the error as toast
Toast.makeText(StudReg.this, error.toString(),Toast.LENGTH_LONG).show();
}
}
);
}
, а мой файл PHP -
<?php
//checking if the script received a post request or not
if($_SERVER['REQUEST_METHOD']=='POST'){
//Getting post data
$stdid=$_POST['stdid'];
$stdpass = $_POST['stdpass'];
$stdadd = $_POST['stdadd'];
$stdphn = $_POST['stdphn'];
$stdemail=$_POST['stdemail'];
//checking if the received values are blank
if($stdid == '' || $stdpass== '' || $stdad == '' || $stdemail=='' || $stphn==''){
//giving a message to fill all values if the values are blank
echo 'please fill all values';
}else{
//If the values are not blank
//Connecting to our database by calling dbConnect script
require_once('connection.php');
//Creating an SQL Query to insert into database
//Here you may need to change the retrofit_users because it is the table I created
//if you have a different table write your table's name
//This query is to check whether the username or email is already registered or not
$sql = "SELECT * FROM student WHERE stud_id=$stdid";
//If variable check has some value from mysqli fetch array
//That means username or email already exist
$check = mysqli_fetch_array(mysqli_query($con,$sql));
//Checking check has some values or not
if(!(isset($check))){
//If check has some value that means username already exist
echo 'studentid does not exist';
}else{
//If username is not already exist
//Creating insert query
$sql = "UPDATE student set password='$stdpass', addrs='$stdad',phn_no=$stdphn,email='$stdemail' WHERE stud_id=$stdid";
//Trying to ins db
if(mysqli_query($con,$sql)){
//If inserted successfully
echo 'successfully registered';
}else{
//In case any error occured
echo 'oops! Please try again!';
}
}
//Closing the database connection
mysqli_close($con);
}
}else{
echo 'error';
}
но в PHP он вообще не получает данные.в почтальоне также я проверил это указывает, что неопределенный индекс stdid одинаково для всех полей данных.Пожалуйста, помогите мне.спасибо миллион заранее