I am sending the 3 integer values from Java to PHP in order to either change or add entries in my database, depending if an entry already exists. I am having trouble with binding the variables and get the following error:
Notice: Undefined index: userid in C:\xampp\htdocs\attendanceradio.php on line 9
Notice: Undefined index: eventid in C:\xampp\htdocs\attendanceradio.php on line 10
Notice: Undefined index: attending in C:\xampp\htdocs\attendanceradio.php on line 11
Notice: Undefined index: attending in C:\xampp\htdocs\attendanceradio.php on line 12
Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement in C:\xampp\htdocs\attendanceradio.php on line 23
In this question I am specifically asking about the Warning that I get, I am new to this and would like to know what I am doing wrong. Any help would be amazing, thanks in advance!
<?php
    $user = 'root';
    $pass = '';
    $db = 'testuser';
    $con=mysqli_connect('localhost', $user, $pass, $db) or die('Unable to connect');
    $userid = $_POST['userid'];
    $eventid = $_POST['eventid'];
    $attending = $_POST['attending'];
    $attending2 = $_POST['attending'];
    $statement = mysqli_prepare($con, 
    'INSERT INTO user_has_event(user_user_id, event_event_id, attendance)
        VALUES (?, ?, ?)
        ON DUPLICATE KEY UPDATE attendance = ?');
    mysqli_stmt_bind_param($statement, 'iiii', $userid, $eventid, $attending, $attending2);
    mysqli_stmt_execute($statement);
    mysqli_stmt_store_result($statement);
    mysqli_stmt_bind_result($statement, $userid, $eventid, $attending, $attending2);
    mysqli_stmt_close($statement);
    mysqli_close($con);
?>
I have also tried:
 $statement = mysqli_prepare($con, 
'INSERT INTO user_has_event(user_user_id, event_event_id, attendance)
    VALUES (?, ?, ?)
    ON DUPLICATE KEY UPDATE attendance = ?');
mysqli_stmt_bind_param($statement, 'iii', $userid, $eventid, $attending);
Java code:
public class ServerRequests {
    ProgressDialog progressDialog;
    public static final int CONNECTION_TIMEOUT = 1000 * 15;
    public static final String SERVER_ADDRESS = "http://10.0.2.2:80/";//Connects to the emulator
    public ServerRequests(Context context) {
        progressDialog = new ProgressDialog(context);
        progressDialog.setCancelable(false);
        progressDialog.setTitle("Processing");
        progressDialog.setMessage("Please wait...");
    }
    public void GetAttendanceDataAsyncTask(Attendance attendance, GetAttendanceCallback attendanceCallBack) {
        progressDialog.show();
        new getAttendanceDataAsyncTask(attendance, attendanceCallBack).execute();
    }    
public class getAttendanceDataAsyncTask extends AsyncTask<Void, Void, Void> {
        Attendance attendance;
        GetAttendanceCallback attendanceCallBack;
        public getAttendanceDataAsyncTask(Attendance attendance, GetAttendanceCallback attendanceCallBack) {
            this.attendance = attendance;
            this.attendanceCallBack = attendanceCallBack;
        }
        @Override
        protected Void doInBackground(Void... params) {
            Map<String, Integer> dataToSend = new HashMap<>();
            dataToSend.put("userid", MainActivity.getUserID());
            dataToSend.put("eventid", EventPage.getEventID());
            dataToSend.put("attending", EventPage.getRadio());
            String encodedStr = StrEncoder.getEncodedData(dataToSend);
            BufferedReader reader = null;
            try {
                URL url = new URL(SERVER_ADDRESS + "/attendanceradio.php");
                HttpURLConnection con = (HttpURLConnection) url.openConnection(); //Opens attendanceradio.php
                con.setConnectTimeout(CONNECTION_TIMEOUT); //Setting timeouts
                con.setReadTimeout(CONNECTION_TIMEOUT);
                con.setRequestMethod("POST"); //Request post
                con.setDoOutput(true);
                OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream());
                writer.write(encodedStr);
                writer.flush();
                StringBuilder sb = new StringBuilder();
                reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
                String line;
                while ((line = reader.readLine()) != null) { //Read until there is something available
                    sb.append(line + "\n");     //Read and save line by line
                }
                line = sb.toString();           //Saving complete data received in string
                //Check values received in Logcat
                Log.i("custom_check", "The values received in the store part are as follows:");
                Log.i("custom_check", line);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (reader != null) {
                    try {
                        reader.close();     //Closing the
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return null;
        }}

 
     
    