Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you reference a html tag in php?
    primarykey
    data
    text
    <p>I want to put in a conditional statement in the below code in order to prevent the PHP Post from running if there is no selection of the "branches" radio buttons.</p> <p>I can't find the syntax to do this correctly. </p> <p>I'm not sure how to refer to a HTML tag in a conditional statement.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script&gt; function myFunction() { alert("Data has been submitted!"); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Reference Stats Input&lt;/h1&gt; &lt;form method="post"&gt; &lt;h2&gt;Select Branch&lt;/h2&gt; &lt;label&gt;&lt;input type="radio" name="branches" value="AR"&gt;AR&lt;/label&gt;&lt;br&gt; &lt;label&gt;&lt;input type="radio" name="branches" value="BK"&gt;BK&lt;/label&gt;&lt;br&gt; &lt;label&gt;&lt;input type="radio" name="branches" value="BR"&gt;BR&lt;/label&gt;&lt;br&gt; &lt;label&gt;&lt;input type="radio" name="branches" value="EM"&gt;EM&lt;/label&gt;&lt;br&gt; &lt;label&gt;&lt;input type="radio" name="branches" value="MD"&gt;MD&lt;/label&gt;&lt;br&gt; &lt;label&gt;&lt;input type="radio" name="branches" value="PT"&gt;PT&lt;/label&gt;&lt;br&gt; &lt;label&gt;&lt;input type="radio" name="branches" value="UR"&gt;UR&lt;/label&gt;&lt;br&gt; &lt;label&gt;&lt;input type="radio" name="branches" value="WA"&gt;WA&lt;/label&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt; Type of Reference question:&lt;select name="refquestion" &lt;br&gt;&lt;br&gt; &lt;option value="ADULT"&gt;ADULT&lt;/option&gt; &lt;option value="CHILD"&gt;CHILD&lt;/option&gt; &lt;option value="JUVENILE"&gt;JUVENILE&lt;/option&gt; &lt;/select&gt;&lt;br&gt;&lt;br&gt; &lt;input name="Submit" type="submit" onclick="myFunction()" value="INPUT"&gt; &lt;?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) } ?&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload