Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The question is looking for to compare the two fields in PHP. Presumably this means that you want to examine them when the form is posted.</p> <p>This means that you'll only have available to you the parts of the field that are sent via the POST -- ie the field <code>name</code> and the <code>value</code>. PHP will never see the <code>id</code> of any of the fields, nor the <code>class</code>, nor any other attributes in the HTML code other than <code>name</code> and <code>value</code>.</p> <p>Therefore the discussion in the comments about whether or not to use <code>id</code> is a somewhat moot point -- even if it is a good point for you to know in general for your HTML code, you can't really use either <code>id</code> or <code>class</code> here anyway because PHP will never see them.</p> <p>You need to take an entirely different approach.</p> <p>[EDITED after question edit]</p> <p>Add the <code>100</code> or <code>200</code>, etc to the <code>value</code> of the <code>image</code> radio buttons, like so:</p> <pre><code>&lt;input type="radio" name="image" value="a_100"/&gt; &lt;input type="radio" name="image" value="b_100"/&gt; &lt;input type="radio" name="image" value="c_100"/&gt; &lt;input type="radio" name="image" value="d_200"/&gt; &lt;input type="radio" name="image" value="e_200"/&gt; &lt;input type="radio" name="image" value="f_300"/&gt; &lt;input type="radio" name="image" value="g_300"/&gt; &lt;input type="radio" name="image" value="h_400"/&gt; </code></pre> <p>(The <code>number</code> radio button set remains unchanged from your question)</p> <p>You can then read it in PHP as follows:</p> <pre><code>$number = $_POST['number']; list($imgNumber, $imgValue) = explode('_',$_POST['image']); </code></pre> <p>You can now compare <code>$number</code> with <code>$imgNumber</code>.</p> <p>Hope that helps.</p> <p>It's worth asking a follow-up question though: What are you trying to achieve here? Is this a validation exersise? ie where you're checking that the user is selecting an <code>image</code> option that matches the <code>number</code> option he's picked? If that's what you're doing, you may find it's more user friendly to use Javascript to filter the options available when they select the <code>number</code> option so that the <code>image</code> radio button set only shows options that are valid for the selected <code>number</code>.</p> <p>This would be an entirely different question, so I won't go into any detail here, but I would suggest that it might be a more user-friendly way of doing things if you did it like that.</p>
    singulars
    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.
    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