Question: Whenever i submit the checkbox when pressing the Save All button, it does not update to the database. How do I debug it ? save.php
Whenever i submit the checkbox when pressing the "Save All" button, it does not update to the database. How do I debug it save.php is in charge of handling submitting the data.
st image: Checkbox code
nd image: Submitform function
rd image: Save all button
th: Home page
save.php:
sessionstart;
includedatabaseconnectionphp;
Check if the request is a POST request with JSON data
if $SERVERREQUESTMETHOD' 'POST' && strpos$SERVERCONTENTTYPE' 'applicationjson false
Get the JSON input
$json filegetcontentsphp:input;
$data jsondecode$json, true;
Process the data here
if $data
Process the sizes
if isset$datasize && $SESSIONlevel
foreach $datasize as $id $sizes
$sizesString implode $sizes;
Use upsert to insert or update sizes
$stmt $connprepareINSERT INTO testdatabaseid size VALUES ON DUPLICATE KEY UPDATE size VALUESsize;
if $stmt
$stmtbindparamis $id $sizesString;
if $stmtexecute
echo jsonencodestatus 'error', 'message' "Error executing statement: $stmterror;
exit;
$stmtclose;
else
echo jsonencodestatus 'error', 'message' "Error preparing statement: $connerror;
exit;
Process sizes that might have been unticked
$existingSizesQuery "SELECT id size FROM testdatabase;
$result $connquery$existingSizesQuery;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
