I've been through a few similar questions for this, however, with my basic knowledge I haven't been able to find an answer that I can tie directly to what I'm trying to achieve.
For instance, I have found answers regarding arrays to store multiple checkbox values. However, I'm not sure if this is what I need as each of the 3 checkboxes i have are for individual columns in the database.
This is my HTML that i have currently for checkboxes etc:
<form action="addNewClient.php" method="POST">
<div class="modal-body">
<p>Please enter the name of the client you wish to create.</p>
<textarea id="addSQLNoteName" placeholder="Enter client name..." name="title" maxlength="25"></textarea>
<p>Teams Packge:</p>
<select name="package">
<option value="SBE">SBE</option>
<option value="Enterprise">Enterprise</option>
</select>
<br />
<input type="checkbox" name="portal" value="1"> Premium Portal
<br />
<input type="checkbox" name="replicated" value="1"> Replicated
<br />
<input type="checkbox" name="client" value="1"> IT Client
<br />
<textarea id="addSQLNoteName" placeholder="Important client info..." name="info" maxlength="25"></textarea>
</div>
<div class="modal-footer footer-sqlnotes">
<button type="submit" class="btn btn-success">Add Client</button>
</div>
</form>
This is my current PHP code and ive made a few comments just showing which ones are the checkboxes:
<?php include 'connectionDetails.php'; ?>
<?php
session_start();
if (isset($_POST['title'], $_POST['package'], $_POST['portal'], $_POST['replicated'], $_POST['client'], $_POST['info']))
{
$title = $_POST['title'];
$package = $_POST['package'];
$portal = $_POST['portal']; //Checkbox
$replicated = $_POST['replicated']; //Checkbox
$client = $_POST['client']; //Checkbox
$info = $_POST['info'];
$stmt = "INSERT INTO Clients (Client, TeamsPackage, Rating, Pos, Neg, PremiumPortal, Replicated, ITClient, ClientInfo) VALUES (?, ?, 0, 0, 0, ?, ?, ?, ?)";
$params = array($title, $package, $portal, $replicated, $client, $info);
$stmt = sqlsrv_query($conn, $stmt, $params);
if ($stmt === false)
{
die( print_r(sqlsrv_errors(), true));
}
header('location: clients.php');
}
else
{
echo "No Data";
}
?>
And so in my database, I have three bit field columns, if checked when submitted it will enter as a 1 otherwise it will enter as a 0.
Like I said, I apologise if another question does answer mine, I just couldn't seem to implement it over to what i am trying to achieve.
At the moment, if all 3 boxes are checked then it will add the client, otherwise it fails the isset() which is what I'm trying to get around at the moment.
isset()and it doesn't get through that conditional. It's hard to say what you want to use/do here though.isset()on a submit button, then the ternaries inside that. Use error reporting and check for errors on the query.