-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPHP_MySQLI_DropDown_Menu_ENUM.php
More file actions
38 lines (31 loc) · 1.83 KB
/
Copy pathPHP_MySQLI_DropDown_Menu_ENUM.php
File metadata and controls
38 lines (31 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
$HTMLPage= <<<HTML
**//INSERT HERE THE HTML CODE YOU ONLY WANT TO SHOW IF THE DROPDOWN MENU HAS BEEN CORRECTLY INSERTED:**
<input type="submit" name="submit" value="Submit Form."/>
<input type="reset" value="Reset Form" />
HTML;
if($myDBObject = new mysqli("**SERVER_HOSTNAME**","**MySQL_USERNAME**","**MySQL_PASSWORD**")){
$myDBObject->select_db("DB_NAME");
if(!$queryResult = $myDBObject->query("SHOW COLUMNS FROM **tableName** WHERE Field=\"**columnName**\"")){
echo "<h2>There was an error while creating the page.</h2>";
}else{
if($queryResult->num_rows == 0){
echo "<h2>Check the table definition.";
}else{
echo"<hr><br><h2>**Title**:</h2>";
$enumString = $queryResult->fetch_array()['Type'];
$enumString = substr($enumString,6,strlen($enumString)-8);
$enumString = str_replace('\'','',$enumString);
$arrayEnumOptions = explode(',',$enumString);
echo "<select name=\"**select_input_name**\" required>";
foreach($arrayEnumOptions as $singleOption){
echo "<option value=\"$singleOption\">$singleOption</option>";
}
echo "</select>";
echo $HTMLPage;
}
}
}else{
echo "<h2>There was an error while creating the page.</h2>";
}
?>