简体   繁体   中英

Save a dropdown list into database

I have a list which is displayed from my database:

<<b>List</b>
                <?php
            $select = "SELECT * FROM quabits.inregistrare";
            $result2 = mysql_query($select);
            ?>
        <form id="raport" name="save">
            <table cellspacing='0' cellpadding='0'>
             <tr><td>Selectează:&nbsp;</td>
             <td><select name="den" id="den" onchange="rulare(this.value)">
             <option value="">Selectați un profesor</option>
            <?php 
            while($row=mysql_fetch_array($result2)){
            echo "<option value='" . $row['Email'] ."'> " .$row['Nume'] ." ". $row['Prenume'] ."</option>";
            }?>
            </select>
            </td></tr>
          </table>
</form>
<input id="save" name="save"  type="submit" value="Submit" action="POST"/>

After the drop down menu I put a button to submit.

And after a value is selected and click for submit, I want to save into my database (quabits table inregistrare) the value. Here I'm lost. Any help ?

If you have a select like the following:

<select name="den" id="den" onchange="rulare(this.value)">
    <option value="">Selectați un profesor</option>
     .....
</select>

You would retrieve the value of the select using $_REQUEST['den'] .

Make sure you add the method type to your form, for example

<form id="raport" name="save" method="POST">

in PHP you would store the POST value:

$den = $_POST['den'];

$den = $_POST['den']; $link = mysqli_connect("host","user","password","database",3306 $sql = "Insert into table ('fieldname') VALUES ('$den'); mysqli_query($link,$sql);

非常基本的解决方案,但我的问题不是很容易理解。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM