如果没有选择“分支”单选按钮,我想在下面的代码中添加一个条件语句,以防止 PHP Post 运行。
我找不到正确执行此操作的语法。
我不确定如何在条件语句中引用 HTML 标记。
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
alert("Data has been submitted!");
}
</script>
</head>
<body>
<h1>Reference Stats Input</h1>
<form method="post">
<h2>Select Branch</h2>
<label><input type="radio" name="branches" value="AR">AR</label><br>
<label><input type="radio" name="branches" value="BK">BK</label><br>
<label><input type="radio" name="branches" value="BR">BR</label><br>
<label><input type="radio" name="branches" value="EM">EM</label><br>
<label><input type="radio" name="branches" value="MD">MD</label><br>
<label><input type="radio" name="branches" value="PT">PT</label><br>
<label><input type="radio" name="branches" value="UR">UR</label><br>
<label><input type="radio" name="branches" value="WA">WA</label><br>
<br>
<br>
<br>
Type of Reference question:<select name="refquestion" <br><br>
<option value="ADULT">ADULT</option>
<option value="CHILD">CHILD</option>
<option value="JUVENILE">JUVENILE</option>
</select><br><br>
<input name="Submit" type="submit" onclick="myFunction()" value="INPUT">
<?php
if(!empty("branches"){
$con = mysql_connect("localhost","root","REDACTED");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("refstats", $con);
$sql="INSERT INTO reftable (branch, statcat)
VALUES
('$_POST[branches]','$_POST[refquestion]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con)
}
?>
</form>
</body>
</html>