Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert to mysql db the selected value from dropdown menu(enum)
    text
    copied!<p>There is a dropdown list in the form which are populated with values from mysql db. The table fields for the dropdown is a <code>enum</code> type. I am trying to <code>insert</code> the value selected by the user into the database. I am only getting as a result a <code>NULL</code>. How can I <code>insert</code> the selected value from the dropdown into the table? <a href="http://webprolearner.ueuo.com/test/google.php" rel="nofollow">SITE</a></p> <p><em>PHP</em></p> <pre><code>&lt;?php $db_con = new mysqli(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE); if(isset($_POST['submit'])) { $db_insert = $db_con-&gt;prepare("INSERT INTO academy (name, type, academy_id) VALUES (?,?,?,?)"); $db_insert-&gt;bind_param('ssi', $_POST['name'], $type_value, $_POST['acad_id']); $db_insert-&gt;execute(); print_r($_POST); } ?&gt; &lt;form action="test7.php" method="POST"&gt; Name: &lt;input type="text" name="name"&gt;&lt;/br&gt; Type: &lt;?php $table_name = "academy"; $column_name = "type"; echo "&lt;select id=\"$column_name\" name=\"$column_name\"&gt;&lt;option&gt;Select one&lt;/option&gt;"; $q = "SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '$table_name' AND COLUMN_NAME = '$column_name'"; $r = mysqli_query($db_con, $q); $row = mysqli_fetch_array($r); //print_r($row); $enumList = explode(",", str_replace("'", "", substr($row['COLUMN_TYPE'], 5, (strlen($row['COLUMN_TYPE'])-6)))); //print_r($enumList); foreach($enumList as $type_value){ echo "&lt;option value='$type_value'&gt;$type_value&lt;/option&gt;"; } echo "&lt;/select&gt;&lt;/br&gt;"; ?&gt; Academy ID: &lt;input type="text" id="acad_id" name="acad_id"&gt;&lt;/br&gt; &lt;input value="SAVE" name="submit" type="submit"&gt; &lt;/form&gt; </code></pre> <p><em>TABLE</em></p> <pre><code>CREATE TABLE IF NOT EXISTS `academy` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(25) DEFAULT NULL, `academy_id` int(11) DEFAULT NULL, `type` enum('INACTIVE','ACTIVE') DEFAULT 'ACTIVE', PRIMARY KEY (`id`) ); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload