I'm making a form where i have to insert in my dB several values from a checkbox btn group into different columns. I also have to insert two different values depending if the btn is checked or not.
I made it work in the following way, but is there another way for this became more simple? It´s a lot of issets :).
Thanks for your time.
Best regards!
NM
<?php
if(isset($_POST["submit"])){
// Create connection
include ('connection.php');
if(isset($_POST['fixvalue']) && ($_POST['fixvalue'] == 0)) {
$fixvalue= "fixvalue";
} else {
$fixvalue= 0;
};
if(isset($_POST['frtvalue']) && ($_POST['frtvalue'] == 0)) {
$valueone= "valueone";
} else {
$valueone= 0;
};
if(isset($_POST['secvalue']) && ($_POST['secvalue'] == 0)) {
$valuetwo= "valuetwo";
} else {
$valuetwo= 0;
};
if(isset($_POST['thevalue']) && ($_POST['thevalue'] == 0)) {
$valuethree= "valuethree";
} else {
$valuethree= 0;
};
if(isset($_POST['fovalue']) && ($_POST['fovalue'] == 0)) {
$valuefour= "valuefour";
} else {
$valuefour= 0;
};
if(isset($_POST['fitvalue']) && ($_POST['fitvalue'] == 0)) {
$valuefive= "valuefive";
} else {
$valuefive= 0;
};
$sql = "INSERT INTO values(fixvalue,valueone,valuetwo,
valuethree,valuefour,valuefive)
VALUES('".$fixvalue."','".$valueone."','".$valuetwo."',
'".$valuethree."','".$valuefour."','".$valuefive."')";
if ($con->query($sql) === TRUE) {
echo'<button class="btn btn-success" style="left:400px;bottom:20px;width:200px;">Sucess</button>';
echo "<script type= 'text/javascript'>alert('New record OK');</script>";
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" $con->error."');</script>";
}
$con->close();
}
?>