Hi guys...I need some help in matching data from results of checkboxs and radio buttons.

My Intentions:

There are 3 radio buttons and 8 check boxes. Users can select any one but cannot don't select at all. I separate the calss and categories because for classes, users can only select 1 option whereas for categories users can select many.
For example, User select class 1 but do not select anything else and click submit...the system will then retrieve that he selected and check the data base if he have the pre requisites to allow him to go through.

Coding for my form:

<form id="applicationoptions" method="post" action="s_apply_now.php">
<div id="optionshead">Class :</div>
<div id="classoptions">
<input type="radio" name="class" value="1" /> Class 1 Permit       
<input type="radio" name="class" value="2" /> Class 2 Permit       
<input type="radio" name="class" value="3" /> Class 3 Permit
</div>
<div id="optionshead2">Categories :</div>
<div id="catoptions">
<input type="checkbox" name="cat" value="1" /> CAT 2PG         
<input type="checkbox" name="cat" value="2" /> CAT 1OR         
<input type="checkbox" name="cat" value="3" /> CAT 2TT <br/><br/>
<input type="checkbox" name="cat" value="4" /> CAT 3PG         
<input type="checkbox" name="cat" value="5" /> CAT 2OR         
<input type="checkbox" name="cat" value="6" /> CAT 3TT <br/><br/>
<input type="checkbox" name="cat" value="7" /> CAT 4PG         
<input type="checkbox" name="cat" value="8" /> CAT 3OR
</div>
<div class="applynext">
<input class="applynextbutton" type="submit" name="applynextbutton" value="PROCEED" />
</div>
</form>

Lets say if user do not select any class, but select CAT 3PG, system will check if user have the pre-requisites before proceeding to next step.

Any one can help me or give me hints?? most importantly is i do not know how to retreieve the values selected from the form.

Thanks in advance guys...greatly appreciate.

Dani AI

Generated

Short, practical fix and why it works (for , building on ): keep the radio group as a single scalar value and name checkboxes as an array. Radios should share the same name (e.g. class) and will submit one value; checkboxes should be cat[] so PHP receives an array. Always validate on the server — client-side checks are convenience only. The processing flow is:

  • read and sanitize the posted values (single int for the radio, an int array for the checkboxes),
  • build the list of prerequisite IDs for the selected class and/or categories,
  • fetch the user's completed qualifications from the DB,
  • compare and reject or allow based on any missing prerequisites.

Example PHP skeleton (processing side — adapt table/column names and DB connection to the project):

<?php
if ($_SERVER['REQUEST_METHOD'] !== 'POST') exit;

// Read + sanitize
$classId = isset($_POST['class']) ? (int) $_POST['class'] : 0;
$cats = (isset($_POST['cat']) && is_array($_POST['cat'])) ? array_map('intval', $_POST['cat']) : [];

// Basic validation
if (!$classId && empty($cats)) {
    // no selection made
    exit('Select a class or at least one category.');
}

// PDO instance (replace with real DSN/credentials)
$pdo = new PDO('mysql:host=localhost;dbname=app', 'user', 'pass', [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);

$prereqs = [];

// class prereqs
if ($classId) {
    $stmt = $pdo->prepare('SELECT prereq_id FROM class_prereqs WHERE class_id = ?');
    $stmt->execute([$classId]);
    $prereqs = array_merge($prereqs, $stmt->fetchAll(PDO::FETCH_COLUMN));
}

// category prereqs
if ($cats) {
    $placeholders = implode(',', array_fill(0, count($cats), '?'));
    $stmt = $pdo->prepare("SELECT prereq_id FROM category_prereqs WHERE cat_id IN ($placeholders)");
    $stmt->execute($cats);
    $prereqs = array_merge($prereqs, $stmt->fetchAll(PDO::FETCH_COLUMN));
}

$prereqs = array_unique($prereqs);

// get user's completed quals (set $userId earlier)
$stmt = $pdo->prepare('SELECT qual_id FROM user_quals WHERE user_id = ?');
$stmt->execute([$userId]);
$have = $stmt->fetchAll(PDO::FETCH_COLUMN);

$missing = array_diff($prereqs, $have);
if ($missing) {
    // handle missing prerequisites
} else {
    // proceed
}

Notes and troubleshooting tips: $_POST['cat'] must be an array — if it is not, the checkbox names are wrong (missing []) or JS altered submission. Use array_map('intval', ...) to force numeric IDs, and always use prepared statements to avoid SQL injection. For UX, add HTML5 required to the radio group (or server-side reject) and a small JS check if at least one checkbox is needed — but never rely on client-side checks for security.

The name should be an array, cat[] and class[] and the verification should go via Javascript or you can pass your values via PHP but that is kind of old school.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.