Here, I am trying to update my data in SQL. Therefore, I have used 000webhost to update and fetch my data from mysql using php. I try to update and fetch data, but it always returning 'uploadAttendanceStatus() data: {"UCEC106":"1"}'. I want an output like this 'uploadAttendanceStatus() data: {"UCEC106":"15"}'.
This is the code which is use in flutter inside a Button Widget.
try {
final response = await http.post(_url, body: {
'roll_number': '1701305',
'course_code': 'UCEC106',
'dept': 'civil,
'attendance': '15',
'date': 'Jan 15',
});
if (response.statusCode == 200) {
var data = response.body;
print('uploadAttendanceStatus() data: $data');
} else {
print('uploadAttendanceStatus.php: ${response.statusCode}');
}
} catch (e) {
print('Catch uploadAttendanceStatus.php: $e');
}
This is the table, where I want to update.
______________________
roll_number | UCEC106 |
______________________
1701305 | 0 |
______________________
This is the php code.
<?php
include "config.php";
$rollNumber = $_POST['roll_number'];
$courseCode = $_POST['course_code'];
$dept = $_POST['dept'];
$attendance = $_POST['attendance'];//I am not aware of php, but i think the problem is here....
$date = $_POST['date'];
if($dept!="" && $rollNumber!="" && $courseCode!="" && $attendance=!"" && $date!=""){
if($dept=="civil"){
$updateRequest = "UPDATE today_civil_attendance_sheet SET $courseCode=$attendance, date='$date'
WHERE roll_number=$rollNumber";
$con->query($updateRequest);
$getRequest = "SELECT $courseCode FROM today_civil_attendance_sheet WHERE
roll_number=$rollNumber";
$result = $con->query($getRequest);
echo json_encode($result->fetch_assoc());
}else{
//another dept..................................
}
}
?>
This is the output: Expected Output: uploadAttendanceStatus() data: {"UCEC106":"15"} Actual Output: uploadAttendanceStatus() data: {"UCEC106":"1"}
Also is there anyway adding that field, like adding 0+5=5. What is the query for that?