How do you reference a html tag in php?
I'm new at html and php. I want to put in a conditional in the below code
and prevent the php post from running if there is no selection of the
"branches" radio buttons. I can't find the syntax to do this correctly.
I'm not sure how to refer to a html tag in a conditional statement. Any
help would be greatly appreciated.
<!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","dyno!mutt");
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>
No comments:
Post a Comment