Page 1 of 1

How to make a dynamic form??

Posted: Fri Sep 30, 2005 11:18 am
by farid
Hi y'all!!

Well here it goes, I have in a web page two radiobuttons, and (this part I do not know how to do it ), it suppose to load info from a database according to the selection of the radio into a select, that is if someone selects the first radiobutton it loads info from one table into the select, and if the second radio is selected, then it loads info from a second table in the same select.

Hoping someone can help me!! :oops:

Posted: Fri Sep 30, 2005 1:27 pm
by Skara

Code: Select all

<input type='radio' name='myradio' value='rowone' />
<input type='radio' name='myradio' value='rowtwo' />

Code: Select all

$valid = array('rowone','rowtwo');
if (in_array($_GET['myradio'],$valid)) { // these two steps are IMPORTANT!! 
  $query = "SELECT {$_GET['myradio']} FROM mytb";
}

Posted: Fri Sep 30, 2005 1:44 pm
by farid
Ok, thanks man, I´ll check it right away!!

Posted: Fri Sep 30, 2005 2:01 pm
by farid
MMh well I do not know but it does not work, my code

Code: Select all

<body>
<table width="430" align="center">
  <tr> 
    <td >Operacion</td>
    <td><div> 
        <input type="radio" name="operacion" value="propuesta">
        Nueva Propuesta</strong></font></div>
      <div>
        <input type="radio" name="operacion" value="actualizacion">
        Actualizaci&oacute;n de Equipos</div></td>
  </tr>
  <tr> 
    <td >Plataforma*</td>
    <td>
  <input type="radio" name="plataforma" value="GSM">
        GSM
  <input type="radio" name="plataforma" value="TDMA">
        TDMA </td>
  </tr>
  <tr> 
    <td>Marca 
      y Modelo</td>
    <td      <input name="marca_modelo" type="text" id="marca_modelo" size="20" maxlength="20">
      </td>
    <td width="165" bgcolor="#24A2C6"><select name="menu1" id="menu1">
        <option>Selecciona la Propuesta</option>
        <?php
			$valid = array('propuesta','actualiza'); 
			if (in_array($_GET['operacion'],$valid)) { // these two steps are IMPORTANT!!  
			@$link_id = mysql_connect("[hostname]", "[login]", "[password]") or die("Connection Failed");
			$select_db = mysql_select_db("[database]",$link_id) or die("Connection Failed");

			$obtiene_gsm=mysql_query("SELECT marca_modelo FROM akit_GSM WHERE propuesta='1' ORDER BY marca_modelo") or die ("No hay propuestas disponibles");
			while ($despliega_gsm=mysql_fetch_array($obtiene_gsm)){
			      print "<option>".$despliega_gsm["promocion"];
    		}
			}else{
			@$link_id = mysql_connect("[hostname]", "[login]", "[password]") or die("Connection Failed");
			$select_db = mysql_select_db("[database]",$link_id) or die("Connection Failed");

			$obtiene_gsm=mysql_query("SELECT marca_modelo FROM akit_TDMA WHERE propuesta='1' ORDER BY marca_modelo") or die ("No hay propuestas disponibles");
			while ($despliega_gsm=mysql_fetch_array($obtiene_gsm)){
			      print "<option>".$despliega_gsm["promocion"];
    		}
			}
			?>
      </select></td>
  </tr>
  <tr> 
    <td height="25" bgcolor="#1C6295"><strong><font color="#FFFFFF" size="2" face="Arial">Promoci&oacute;n</font></strong></td>
    <td height="25" bgcolor="#24A2C6"><strong><font color="#000000" size="2" face="Arial"> 
      <input name="promocion" type="text" id="promocion" value="-" size="20" maxlength="40">
      </font></strong></td>
    <td height="25" bgcolor="#24A2C6"><select name="menu2" id="menu2">
        <option>Selecciona la Promoci&oacute;n</option>
        <?php
			@$link_id = mysql_connect("[hostname]", "[login]", "[password]") or die("Connection Failed");
			$select_db = mysql_select_db("[database]",$link_id) or die("Connection Failed");

			$res_gsm=mysql_query("SELECT promocion FROM akit_GSM WHERE propuesta='1'") or die ("No hay propuestas disponibles");
			while ($obten_gsm=mysql_fetch_array($res_gsm)){
			      print "<option>".$obten_gsm["promocion"];
    		}?>
      </select></td>
  </tr>
  <tr> 
    <td height="25" colspan="3">&nbsp;</td>
  </tr>
  <tr> 
    <td height="25" colspan="3"><div align="center"> 
        <input type="submit" name="Submit" value="Submit">
      </div></td>
  </tr>
</table>
<body>

Posted: Fri Sep 30, 2005 2:19 pm
by Skara
<input type="radio" name="operacion" value="actualizacion">
$valid = array('propuesta','actualiza');
And I'd take out your username and password on the connect line... -_-'

Posted: Fri Sep 30, 2005 5:05 pm
by farid
Ok, I've already fix it, but in the select does not appear the info, oh about the login and password there is no prob, the server is in a LAN connection, thanks. :lol: