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. Quote Link to comment 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"]); Quote Link to comment Share on other sites More sharing options...
kreut Posted February 15, 2011 Author Share Posted February 15, 2011 Perfect! Thanks so much.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.