benchew0904 Posted November 20, 2011 Share Posted November 20, 2011 Hi I want to add student from a dropdown list to database but I have some problem. This is my select dropdown menu code <form name ="student" method = "POST" action ="confirmation.php"> <select name="name"> <option selected>Select Student</option> <?php $arrStudent = executeSelectQuery("select * FROM user "); for ($i = 0; $i < count($arrStudent); $i++) { $student_result = $arrStudent[$i]['student_id']; $name_result = $arrStudent[$i]['student_name']; ?> <option value="<?php echo $id_result; ?>"><?php echo $id_result; ?>, <?php echo $name_result; ?></option> <?php } ?> </select> </form> The output in the dropdown menu look something like this: 1, Alvin 2, Benny 3, Charles 4, Daniel 5, Eva and so on... After submitting the form, it will proceed to confirmation.php page. At the confirmation page, I have the following variable: $student_result = $_REQUEST['student_id']; $name_result = $_REQUEST['student_name']; I want to insert to database with the following insert query $sql = "INSERT INTO student(student_id, student_name) VALUES ('". $student_result . "', '". $name_result ."')"; $insert = executeInsertQuery($sql); It can insert successfully but, it will not insert the student_name. May I know where I did wrongly? Thanks Ben Chew Quote Link to comment https://forums.phpfreaks.com/topic/251478-select-menu/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 20, 2011 Share Posted November 20, 2011 Your form's select field is named 'name' - name="name". You would need to reference that same name in your php code using $_POST['name'] Quote Link to comment https://forums.phpfreaks.com/topic/251478-select-menu/#findComment-1289728 Share on other sites More sharing options...
benchew0904 Posted November 20, 2011 Author Share Posted November 20, 2011 Sorry, I don't quite get what you mean.. Is it at the confirmation.php, i need to have the following: $name = $_REQUEST['name']; $student_result = $_REQUEST['student_id']; $name_result = $_REQUEST['student_name']; Quote Link to comment https://forums.phpfreaks.com/topic/251478-select-menu/#findComment-1289730 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.