这是我的组合框页面编码:
<?php
echo "<form method=post align=center>
<div id=myDiv>
<select name=userselect>
<option value=empty></option>
<option value=Confirm> Confirm </option>
<option value=Processing> Processing </option>
<option value=Pending> Pending </option>
<option value=Cancelled> Cancelled </option>
</select>
<button type=button name=combobox value=combobox onclick=loadXMLDoc()>Update</button>
</div>
</form>";
?>
这是我的PHP代码(另一页):
<?php
if (isset($_POST['combobox']))
{
$userselect = $_POST['userselect'];
echo $userselect;
}
?>
如果用户在组合框中选择一个值,该值应存储在db中,然后显示它们的选择内容。例如,如果用户选择CONFIRM选项后该值存储在db中,则显示CONFIRM而不是该组合框表单和按钮。在这里,我可以成功地在db中存储组合框值。这不是问题然后在这里我使用ajax方法来显示msg而不是按钮位置。现在,我想要用户选择它应该显示相同的值。检查以上编码并回复我的建议......
答案 0 :(得分:0)
用以下代码替换您的代码:
<?php
//Connect To your Database File..
//After Connecting To Databse
$combo = mysqli_real_escape_string('yourconnectionlink', $_POST['userselect'])
echo "<form method='post' action='youractionfile.php' align='center'>
<div id='myDiv'>
<select name='userselect'>
<option value='empty'></option>
<option value='Confirm'> Confirm </option>
<option value='Processing'> Processing </option>
<option value='Pending'> Pending </option>
<option value='Cancelled'> Cancelled </option>
</select>
<input type='button' name='combobox' value='combobox'>Update</button>
</div>
</form>";
//Insert Data into Database File
if($_POST['userselect'])) {
if(isset($_POST['userselect'])) {
$query = "INSERT INTO tablename (your field names) VALUES ('".$combo."')";
$res = mysqli_query('yourconnectionlink', $query);
echo '1 row inserted';
}
}
?>
答案 1 :(得分:0)
最后我得到了我想要的东西。不使用ajax方法我可以将数据存储到db然后组合框,如果我们更新了状态,按钮会永久隐藏。这是我最后的编码...
if ( $a_row['status'] != 'empty' ) {
echo "\t<td>" . $a_row[$status] . "</td>\n";
}
else {
echo "\t<td><form action=statusdb.php method=post>
<select name=update>
<option value=empty></option>
<option value=Confirm>Confirm</option>
<option value=Processing>Processing</option>
<option value=Pending>Pending</option>
<option value=Cancelled>Cancelled</option></select>
<input name=id type=hidden value='".$a_row['slno']."';>
<input type=submit value=Update>
</form>
</td>\n";
}
statusdb编码:
if (isset($_POST['id']))
{
$id = mysql_real_escape_string($_POST['id']);
$update= mysql_real_escape_string($_POST['update']);
$sql = mysql_query("UPDATE guest_details SET status = '$update' WHERE slno = '$id'");
if(!$sql)
{
die("Error" .mysql_error());
}
}
我发布了另一个问题(php combobox & button should hide once updated into mysql db and show success message instead of combobox & button place.)。我得到了答案的帮助......所以,只有我在这里发布了正确答案..