user1444442
user1444442

Reputation: 109

Getting checkbox text value

I am having bit of issue getting text value of database populated check boxes.Below is my query that populate check box depending on my query.

if (isset($_POST['submitCourseCode'])) { 

    $aElective = $_POST['electiveModules'];
     foreach(array_keys($aElective) as $elec) {
     echo "$elec";
  }
}
echo "<form name=\"psform\" action=\"plotyourcourseGraphpSave.php\" method=\"post\">";
$moduleQuery = "SELECT module.*,group_elective_modules.moduleID 
                FROM module,group_elective_modules 
                WHERE group_elective_modules.courseName = '$courseTitle' 
                AND group_elective_modules.yr = '$year' 
                AND group_elective_modules.moduleID = module.ID ";

$moduleResult = mysql_query($moduleQuery );
while ($row = mysql_fetch_array($moduleResult)) {

   echo "<input type=\"checkbox\" name=\"electiveModules[]\" value=\"{$row['title']}\" /> {$row['title']}<br />";                                                       
}                                                                                                                                   
echo "<input type=\"submit\" name=\"submitCourseCode\" value=\"Submit\" />  
</form>";

Here are the screen shots enter image description here

Result of selected check boxes

enter image description here

But this is what I want

Threshold French
French for Reading Purposes I
German Language (Beginner [00] Level)
German Language (Intermediate [05] Level)

So when I select few of the check boxes and I press submit,it passes on numeric value of check boxes I picked but I want the text value instead. Any help on this please ?

Upvotes: 1

Views: 708

Answers (2)

devanand
devanand

Reputation: 5290

$aElective = $_POST['electiveModules'];
 foreach( $aElective as $key => $value ) {
    echo "$key: $value";
}

is this working for you?

Upvotes: 0

ivantedja
ivantedja

Reputation: 2553

this is the incorrect code:

foreach(array_keys($aElective) as $elec)

because you use array_keys, it will get the index instead of the value, it should be:

foreach($aElective as $elec)

Upvotes: 1

Related Questions