1

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 ?

1
  • That's odd because you echo the same variable {$row['title']} for both the value of the checkbox and the label next to it... Are you sure you got the $_POST['electiveModules'] Array value ? Commented Aug 5, 2012 at 12:59

2 Answers 2

1

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)

Sign up to request clarification or add additional context in comments.

Comments

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

is this working for you?

1 Comment

@wkaha.Thanks a lot.It's working now. Using the predefined function array_keys() was causing the problem. Thanks for the suggestion and have a great day !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.