kreut Posted February 15, 2011 Share Posted February 15, 2011 Hello, I'm using a dynamically created select menu for a user to make a choice which will then be put in my database with the following code: <select> <?php foreach ($course_number as $row) { echo "<option value = '{$row['course_id']}'"; if ($errors && $_POST["course_id"] == $row['course_id']) {echo 'selected = "selected"'; } echo ">{$row['course_number']}</option>"; } ?> Unfortunately, I'm having some problems figuring out how to pull off the selected value. Right now my database portion looks like this: $data = array('assignment_name' => $_POST['assignment_name'], 'due_date' => $_POST['due_date'], 'course_id' => $_POST["row['course_id']"]); $inserted = $dbWrite->insert('assignments_instructors',$data) While the assignment_name and due_dates work (they come from text fields), my course_id gives me an Undefined index: row['course_id'] error. Any help would be appreciated. Thank you. Link to comment https://forums.phpfreaks.com/topic/227750-value-of-a-post-from-a-select-menu/ Share on other sites More sharing options...
zenlord Posted February 15, 2011 Share Posted February 15, 2011 That doesn't look right: $_POST["row['course_id']"] You should add name="courseid" to your <select> and then change the line 'course_id' => $_POST["row['course_id']"]); to 'course_id' => $_POST["courseid"]); Link to comment https://forums.phpfreaks.com/topic/227750-value-of-a-post-from-a-select-menu/#findComment-1174524 Share on other sites More sharing options...
kreut Posted February 15, 2011 Author Share Posted February 15, 2011 Perfect! Thanks so much.... Link to comment https://forums.phpfreaks.com/topic/227750-value-of-a-post-from-a-select-menu/#findComment-1174557 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.