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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.