How To Auto Assign Value To <Option> Tag In PHP?

Hello Guys,

I m Building A Chat Application…in which i have 2 different user types like Admin & Merchant…I Have Taken User type A for Admin & M for Merchant…First I have Created Only Single LogIn Form for both user types & given DropDown So that If He Selects Merchant then it will assign value M to user type…now i have to create another LogIn form for Merchant…so how can i Auto Assign Value Of user type without displaying it on Form at User Side !! :frowning:

I am Providing my Both Codes For LogIn Just Help Me !!
Old Code For Both Admin & Merchant.

<form action="index.php" method="post">
  <table width="350" border="0" align="center" cellpadding="10" cellspacing="0" bgcolor="#FFFFFF" class="small_grey_border">
    <tr>
      <td width="346"><div align="center"><strong><font size="5">       
      Login</font></strong></div></td>
    </tr>
    <tr>
      <td>	  <div align="center">
          <p><font color="#FF0000" face="Tahoma"><strong> <?php echo $login_message; ?> 
            </strong></font></p>
          <table width="332" border="0" cellspacing="0" cellpadding="2">
            <tr>
              <td width="126" nowrap><div align="right">Username:</div></td>
              <td width="148" nowrap><font face="verdana" size="2"><b>
                <input name="user" class="input" maxlength="100">              
              </b></font></td>
            </tr>
            <tr>
              <td><div align="right">Password:</div></td>
              <td><font face="verdana" size="2"><b>
                <input name="pass" type="password" class="input" maxlength=20>
              </b></font></td>
            </tr>
             <tr>
              <td><div align="right">Are you Merchant?:</div></td>
              <td><font face="verdana" size="2"><b><select name="usertype"><option value="A">No</option><option value="M">Yes</option></select>
               
              </b></font></td>
            </tr>
            <tr>
              <td colspan="2"><div align="center"><font face="verdana" size="2"><b>
                  <input type="submit" value="Login" name="sublogin" class="input">
              </b></font></div></td>
            </tr>
          </table>
          </div>
	  </td>
    </tr>
  </table>
</form>

New Code For Merchant.

<form action="index.php" method="post">
  <table width="350" border="0" align="center" cellpadding="10" cellspacing="0" bgcolor="#FFFFFF" class="small_grey_border">
    <tr>
      <td width="346"><div align="center"><strong><font size="5">       
      Merchant Login</font></strong></div></td>
    </tr>
    <tr>
      <td>	  <div align="center">
          <p><font color="#FF0000" face="Tahoma"><strong> <?php echo $login_message; ?> 
            </strong></font></p>
          <table width="332" border="0" cellspacing="0" cellpadding="2">
            <tr>
              <td width="126" nowrap><div align="right">Username:</div></td>
              <td width="148" nowrap><font face="verdana" size="2"><b>
                <input name="user" class="input" maxlength="100">              
              </b></font></td>
            </tr>
            <tr>
              <td><div align="right">Password:</div></td>
              <td><font face="verdana" size="2"><b>
                <input name="pass" type="password" class="input" maxlength=20>
              </b></font></td>
            </tr>
             <tr>
              <td><div align="right">Are you Merchant?:</div></td>
              <td><font face="verdana" size="2"><b><select name="usertype" ><option value="M">Yes</option></select>
                            
              </b></font></td>
            </tr>
            <tr>
              <td colspan="2"><div align="center"><font face="verdana" size="2"><b>
                  <input type="submit" value="Login" name="sublogin" class="input">
              </b></font></div></td>
            </tr>
          </table>
          </div>
	  </td>
    </tr>
  </table>
</form>

Use a hidden field.

Yeah a hidden field will work. Not sure if it will be secure tho, is that the only way to differentiate between merchants and admin?

The hidden field is as secure as a drop down list would be.

In both cases you need to check that the login used has that level of access once they fill out the form.

Of course. You must always check all input. But I wasn’t saying it’s more secure. The OP said he needed a form where the drop down list would only have one, fixed value that can’t be changed by the user, and shouldn’t be visible to the user. A hidden field would be a good solution, I think.