Jump to content

Select menu


benchew0904

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/251478-select-menu/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.