【发布时间】:2018-10-12 07:50:17
【问题描述】:
从数据库查询中填充 HTML 选项的代码摘录:
<?php
// Connect to the database
$mydb = new wpdb('***','***','***','***');
// run the query to fetch the options
$rows = $mydb->get_results("select distinct(Region) from tblusers order by
Region asc;");
?>
<!-- Form -->
<form method='post' action='success.php'>
<b><h1>Stuur SMS aan Streek</h1></b>
<b>Kies Streek:</b>
<select id='txtReg' name='txtReg'></option>
<?php
// populate the options
foreach ($rows as $row) {
echo "<option value=$row->Id>$row->Region ? 'selected="selected"' : ''
</option>";
}
?>
</select>
<br/>
<b>Boodskap:</b>
<textarea id='txtMsg' name='txtMsg' rows=5 cols=65 style='width:50%;'>
</textarea>
<br/>
<input type='reset' value='Kanselleer'> | <input class="button"
type='submit' value='Stuur SMS aan Streek'>
</form>
必须显示所选选项的success.php页面:
<?php
$txtReg = $_POST['txtReg'];
echo $txtReg;
一切正常,除了我从下拉列表中选择一个选项时,我如何将它传递到成功页面,因为当我尝试回显变量时它没有显示。
【问题讨论】:
-
请注意:选择中的选项是从数据库查询中填充的。然后从下拉列表中选择一个选项,然后需要将该选项值传递到成功页面。
-
是的,看看我的答案并进行更改,它应该适合你。
标签: php mysql wordpress variables