我创建了一个测试表单,只是为了尝试将来自性别表(包含:(1)Male(2)Female)的单选按钮值发送到另一个名为ajebaje
的MySQL表。我现在遇到问题。下面的代码只是一个测试,我希望单选按钮提交值,但它不是。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> ajebaje </title>
</head>
<body>
<form name="form1" action= "<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<table width="20%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td><h4> Student's Gender </h4></td>
<td>
<?php
$con=mysqli_connect("localhost", "root", "ew6wLoLOro", "result");
$sql=mysqli_query($con, "select gender_sl_no, gender_name from gender")
while($row=mysqli_fetch_array($sql))
{
echo '<table>
<input type="radio" name="sexbd" checked="checked"/>'.$row['gender_name'].'
</table>';
}
?>
</td>
</tr>
<tr>
<td> </td>
<td><input type ="submit" name="submit"/> </td>
</tr>
</table>
</form>
<?php
$con=mysqli_connect("localhost", "root", "ew6wLoLOro", "result");
$sexbd = $_POST['sexbd'];
if(isset($_POST['submit']))
{
echo $que="Insert into ajebaje VALUES(default,'$sexbd' )";
echo " ";
echo "Your Data Inserted";
$result = mysqli_query($con,$que);
}
?>
</body>
</html>
答案 0 :(得分:0)
默认情况下,它应该在表单中发送public ActionResult VendorOrderListPartial()
{
var model = VendorManager.GetAllVendorOrders();
ViewBag.paging = GlobalSettingsInfo.GridPageSize;
var grid = this.gridMvcHelper.GetAjaxGrid(model.AsQueryable().OrderByDescending(x => x.OrderId));
return View("VendorOrderListPartial", grid);
}
@Html.Grid(Model).Named("VendorOrderListPartial").Columns(columns =>
{
columns.Add(c => c.OrderNo).Titled("Ord#").Filterable(true);
columns.Add(c => c.OrderDate).Format("{0:dd/MM/yyyy}").Titled("Order Date").Filterable(true);
columns.Add(c => c.ProdStatus).Titled("Prod.Status").Filterable(true);
columns.Add(c => c.OrderAmount).Titled("Total Amount").Filterable(true);
columns.Add().Titled("View").Filterable(false).RenderValueAs(o => Html.ActionLink("View", "VendorOrderDetailView", "WebVendor", new { id = o.OrderId }, null)).Encoded(false).Sanitized(false);
}).WithPaging(@ViewBag.paging).Sortable(true)
。
要从表单发送值,需要在input标记中定义value属性。像这样:
sexbd: on
,呈现的表单如下所示:
echo '<table>
<input type="radio" name="sexbd" checked="checked" value='.$row['gender_name'].'/>'.$row['gender_name'].'
</table>';
现在,提交的值将为<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> ajebaje </title>
</head>
<body>
<form name="form1" action= "/test" method="post">
<table width="20%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td><h4> Student's Gender </h4></td>
<td>
<table>
<input type="radio" name="sexbd" checked="checked" value="Male"/> Male
</table>
<table>
<input type="radio" name="sexbd" checked="checked" value="Female"/> Female
</table>
</td>
</tr>
<tr>
<td> </td>
<td><input type ="submit" name="submit"/> </td>
</tr>
</table>
</form>
</body>
</html>
或sexbd: Male