Jump to content

Do i use a form or is it a subform ?


swatisonee

Recommended Posts

Hi,

I have a form where i receive variables for some product models and specs based on product name that has been obtained from the previous script.
I was wondering if i could create a subform(??) so that when i select a product name in script1, the model and specs pop up in the same script for a selection of each of those too and finally all 3 variables are passed into another form for inserting into a table.

The thing is i'm not sure i can do this without using anything complicated. I got to the foll.stage and then realised that the variable using ISSET $_GET was not getting captured and so the next part was not getting activated. I'm also not sure whether i should be using the function showForm() or any other.

Anyway , if someone could tell me what i need to change in the foll. script, i'd be really thankful.

Swati

[code]

<td>Ags:<select name="ag"><option value="">[Select One]
      <?php

mysql_connect("localhost", $dbname, $dbpasswd )
        or die ("Unable to connect to server.");

mysql_select_db($database)
        or die ("Unable to select database.");

$result = mysql_query("SELECT * FROM `Agix` WHERE uid='$uid' ORDER BY `Name` asc ");

if ($myrow = mysql_fetch_array($result)) {

  do {

    printf("<option>
      %s", $myrow["Name"]);

  } while ($myrow = mysql_fetch_array($result));

    echo "</select>\n";

}
?></td>

if ( isset($_GET[ "ag" ]) )  // Note : This is where the value of $ag has to come but does not.

{



<td>Model:<select name="model"><option value="">[Select One]
<?php

mysql_connect("localhost", $dbname, $dbpasswd )
        or die ("Unable to connect to server.");

mysql_select_db($database)
        or die ("Unable to select database.");

$result = mysql_query("SELECT * FROM `Ags` WHERE `Name`='$ag'");

if ($myrow = mysql_fetch_array($result) ) {

$id = $myrow['Agid'];
$result2 = mysql_query("SELECT DISTINCT `Model` FROM `Products` WHERE `Agid`=$id  ORDER BY `Model` asc ");

if ($myrow2 = mysql_fetch_array($result2)) {

do {
    printf("<option>%s", $myrow2["Model"]);

  } while ($myrow2 = mysql_fetch_array($result2));
} else {
    echo("No model entries found.");
    }
}
?>
</select></td>

<td>Specs:<select name="specs"><option value="">[Select One]

<?php
mysql_connect("localhost", $dbname, $dbpasswd )
        or die ("Unable to connect to server.");

mysql_select_db($database)
        or die ("Unable to select database.");

$result = mysql_query("SELECT * FROM `Ags` WHERE `Name`='$ag'");

if ($myrow = mysql_fetch_array($result) ) {

$id = $myrow['Agencyid'];
$result2 = mysql_query("SELECT DISTINCT `Specs` FROM `Products` WHERE Agid=$id  ORDER BY `Specs` asc ");

if ($myrow2 = mysql_fetch_array($result2)) {

do {
    printf("<option>%s", $myrow2["Specs"]);

  } while ($myrow2 = mysql_fetch_array($result2));
} else {
    echo("No specifications found.");
}
}
?>
</select></td>
}
[/code]
Link to comment
Share on other sites

After days of struggle i've got one dropdwon list to work. The second one just lists all the options available not just those pertaining to the item selected in List 1. I havent even gone to the 2nd pulldown(not popup , sorry !) till i get this first one working.

This part is just not working (probably among many others!):

[code=php:0]if(isset($ag) and strlen($ag) > 0)[/code]

I now get an error " you have error in your sql syntax....on line 1" as soon as a choice from List1 is made. I have bored a whole thru the screen and had to visit an ophthamologist in the bargain because my eyes couldnt take it anymore ! (Seriously ! - he's recommended time out but no can do till this darned problem is over)

[code]<? include("protect.php"); ?>

<font face="Tahoma" size="2" color="#800080">

<html>

<head>
  
  <meta http-equiv="Content-Type"
  content="text/html; charset=iso-8859-1">
  
  <title>
  Add an product
  </title>
  

<script language=JavaScript>
function reload(form)
{
var val=form.ag.options[form.ag.options.selectedIndex].value;
self.location='add_new_product1.php?ag=' + val;
}
</script>
</head>
<?php
$cid = $_POST["choice"];
?>
<div align="center">

<table>

<body bgcolor="#F0F4FF">

<p align="center">
  <font color="#3366FF" face="Tahoma">
  <strong>
  Form
  to add a product
  </strong>
  </font>
</p>

<form method="post" action="add_new_product2.php?uid=
  <? echo $uid ?>
  "onclick="highlight(event)">
  
  <?php
  mysql_connect("localhost", $dbname, $dbpasswd )
  or die ("Unable to connect to server.");
  mysql_select_db($database)
  or die ("Unable to select database.");
  $sql1 = "SELECT * FROM `Customer` WHERE `Customerid`= $cid ";
  $result1 = mysql_query($sql1) or die (mysql_error());
  $myrow1 = mysql_fetch_array($result1);
  ?>
  
  <table border="1" width="50%" align="center">
    
    <tr>
      
      <td align="center" width="15%">
        <font color="#3366FF" face="Tahoma" size="2">
        <strong>
        <p align="center">
          Company
          </font>
        </td>
        
        <td colspan="2" width="35%">
          <font color="#3366FF" face="Tahoma" size="2">
          <strong>
</P>

          <p align="center">
        Ags
        </font>
      </td>
      
    </tr>
    
    <tr>
      
      <td align="center" width="15%"><input type=hidden name="customer"  value="
        <? echo $myrow1["Company"] ?>" size="15">
        <input type=text name="customer"  value="<? echo $myrow1["Company"]?>
        " disabled="true" size="15" >  </td>
      
      <td colspan="2" width="35%">
       <?php

            $sqla = "SELECT * FROM `Ags_hb` WHERE uid='$uid' ORDER BY `Name` asc";

            $resulta=mysql_query($sqla);

            if(isset($ag) and strlen($ag) > 0){

$sqlb = "SELECT DISTINCT `Model` FROM `Products` WHERE `Agid`= $ag  ORDER BY `Model` asc";

           $resultb=mysql_query($sqlb);
}
          

else
{$resultb=mysql_query("SELECT DISTINCT `Model` FROM `Products` ORDER BY `Model` asc"); }


echo "<select name='ag' onchange=\"reload(this.form)\"><option value=''>Select one</option>";

while($myrowa = mysql_fetch_array($resulta)) {
if($myrowa['Agid']==@$ag)
{
echo "<option selected value='$myrowa[Agid]'>$myrowa[Name]</option>"."<BR>";}
else
{echo  "<option value='$myrowa[Agid]'>$myrowa[Name]</option>";}
}
echo "</select>";
?></td></tr>

<tr>
        <td></td>
        <td></td>
        <td>Model:
        <?
     echo "<select name='model'><option value=''>Select one</option>";
while($myrowb = mysql_fetch_array($resultb)) {
echo  "<option value='$myrowb[Model]'>$myrowb[Model]</option>";
}
echo "</select>";
?>  </td>
              
              <td>  Specs:   </td>
                  //TO BE DONE  EXACTLY LIKE FOR MODEL
                  
                </tr>          
              </table>            
            </div>
            
            <p>   <p>
            
            <table border="1" width="80%" align="center">
              
              <tr>
                
                <td width="90%" align="center">
                  <font color="#3366FF" face="Tahoma" size="2">
                  <strong>
                  <p align="center">
                    Action
                    </font>
                    
                  </td>
                  
                </tr>
                
                <tr>
                  <td width="90%" align="center">
                    
                    <?
                    $cols = 90;
                    $lines_count = count(explode("\n", wordwrap($action_init, $cols)));
                    print '
                    <textarea rows="'.$lines_count.'" cols="'.$cols.'">
                    '.$action_init.'
                    </textarea>
                    ';
                    ?>
                    
                  </td>
                </tr>
                
              </table>
              
            </center>
          </div>
          
</P>

          <p>
        <p>
          
          <table border="1" cellspacing="1" width="100%" bgcolor="#0000FF">
            
            <tr>
              
              <td width="50%" bgcolor="#3366FF">
</P>

                <p align="center">
              <font
              color="#FFFFFF" size="2" face="Tahoma">
              Please click this button just
              once to avoid any errors.
              <input type="submit" value="Submit">
              </font>
            </p>
            
          </td>
          
        </tr>
        
      </table>
      
</form>[/code]
Link to comment
Share on other sites

Oops...going blind - instead og hitting the reply button, i went an edited the earlier post ! Anyway this is my situ as on date - and look to some help from other posters. Thanks !

[!--quoteo(post=358924:date=Mar 27 2006, 10:54 AM:name=swatisonee)--][div class=\'quotetop\']QUOTE(swatisonee @ Mar 27 2006, 10:54 AM) [snapback]358924[/snapback][/div][div class=\'quotemain\'][!--quotec--]
After days of struggle i've got one dropdwon list to work. The second one just lists all the options available not just those pertaining to the item selected in List 1. I havent even gone to the 2nd pulldown till i get this first one working.

This part is just not working (probably among many others!):

[code=php:0]if(isset($ag) and strlen($ag) > 0)[/code]

I now get an error " you have error in your sql syntax....on line 1" as soon as a choice from List1 is made. I have bored a whole thru the screen and had to visit an ophthamologist in the bargain because my eyes couldnt take it anymore ! (Seriously ! - he's recommended time out but no can do till this darned problem is over)

[code]<? include("protect.php"); ?>

<font face="Tahoma" size="2" color="#800080">

<html>

<head>
  
  <meta http-equiv="Content-Type"
  content="text/html; charset=iso-8859-1">
  
  <title>
  Add an product
  </title>
  

<script language=JavaScript>
function reload(form)
{
var val=form.ag.options[form.ag.options.selectedIndex].value;
self.location='add_new_product1.php?ag=' + val;
}
</script>
</head>
<?php
$cid = $_POST["choice"];
?>
<div align="center">

<table>

<body bgcolor="#F0F4FF">

<p align="center">
  <font color="#3366FF" face="Tahoma">
  <strong>
  Form
  to add a product
  </strong>
  </font>
</p>

<form method="post" action="add_new_product2.php?uid=
  <? echo $uid ?>
  "onclick="highlight(event)">
  
  <?php
  mysql_connect("localhost", $dbname, $dbpasswd )
  or die ("Unable to connect to server.");
  mysql_select_db($database)
  or die ("Unable to select database.");
  $sql1 = "SELECT * FROM `Customer` WHERE `Customerid`= $cid ";
  $result1 = mysql_query($sql1) or die (mysql_error());
  $myrow1 = mysql_fetch_array($result1);
  ?>
  
  <table border="1" width="50%" align="center">
    
    <tr>
      
      <td align="center" width="15%">
        <font color="#3366FF" face="Tahoma" size="2">
        <strong>
        <p align="center">
          Company
          </font>
        </td>
        
        <td colspan="2" width="35%">
          <font color="#3366FF" face="Tahoma" size="2">
          <strong>
</P>

          <p align="center">
        Ags
        </font>
      </td>
      
    </tr>
    
    <tr>
      
      <td align="center" width="15%"><input type=hidden name="customer"  value="
        <? echo $myrow1["Company"] ?>" size="15">
        <input type=text name="customer"  value="<? echo $myrow1["Company"]?>
        " disabled="true" size="15" >  </td>
      
      <td colspan="2" width="35%">
       <?php

            $sqla = "SELECT * FROM `Ags_hb` WHERE uid='$uid' ORDER BY `Name` asc";

            $resulta=mysql_query($sqla);

            if(isset($ag) and strlen($ag) > 0){

$sqlb = "SELECT DISTINCT `Model` FROM `Products` WHERE `Agid`= $ag  ORDER BY `Model` asc";

           $resultb=mysql_query($sqlb);
}
          

else
{$resultb=mysql_query("SELECT DISTINCT `Model` FROM `Products` ORDER BY `Model` asc"); }
echo "<select name='ag' onchange=\"reload(this.form)\"><option value=''>Select one</option>";

while($myrowa = mysql_fetch_array($resulta)) {
if($myrowa['Agid']==@$ag)
{
echo "<option selected value='$myrowa[Agid]'>$myrowa[Name]</option>"."<BR>";}
else
{echo  "<option value='$myrowa[Agid]'>$myrowa[Name]</option>";}
}
echo "</select>";
?></td></tr>

<tr>
        <td></td>
        <td></td>
        <td>Model:
        <?
     echo "<select name='model'><option value=''>Select one</option>";
while($myrowb = mysql_fetch_array($resultb)) {
echo  "<option value='$myrowb[Model]'>$myrowb[Model]</option>";
}
echo "</select>";
?>  </td>
              
              <td>  Specs:   </td>
                  //TO BE DONE  EXACTLY LIKE FOR MODEL
                  
                </tr>          
              </table>            
            </div>
            
            <p>   <p>
            
            <table border="1" width="80%" align="center">
              
              <tr>
                
                <td width="90%" align="center">
                  <font color="#3366FF" face="Tahoma" size="2">
                  <strong>
                  <p align="center">
                    Action
                    </font>
                    
                  </td>
                  
                </tr>
                
                <tr>
                  <td width="90%" align="center">
                    
                    <?
                    $cols = 90;
                    $lines_count = count(explode("\n", wordwrap($action_init, $cols)));
                    print '
                    <textarea rows="'.$lines_count.'" cols="'.$cols.'">
                    '.$action_init.'
                    </textarea>
                    ';
                    ?>
                    
                  </td>
                </tr>
                
              </table>
              
            </center>
          </div>
          
</P>

          <p>
        <p>
          
          <table border="1" cellspacing="1" width="100%" bgcolor="#0000FF">
            
            <tr>
              
              <td width="50%" bgcolor="#3366FF">
</P>

                <p align="center">
              <font
              color="#FFFFFF" size="2" face="Tahoma">
              Please click this button just
              once to avoid any errors.
              <input type="submit" value="Submit">
              </font>
            </p>
            
          </td>
          
        </tr>
        
      </table>
      
</form>[/code]
[/quote]
Link to comment
Share on other sites

Its the first i'm seeing it - i will read thru it. Thanks for the link.

I have though got the dd to work though its not too clean a code. My only problem now is to find a way to pass the value of $cid as a hidden from the current form to the next . When i put the value prior to the form action , it just gives me a blank page...

[code]<?php
$cid = $_POST["choice"];

?>
<input type="hidden" name="cid" value="<? echo $cid ?>">


<form method="post" action="add_new_product2.php?uid= <? echo $uid ?>&cid = <? echo $cid ?>">[/code]






Link to comment
Share on other sites

Hi

Problem is once the dropdown is selected, the values that were getting passed into the script from the previous page and which are needed to get passed to the next disappear .I know i'm making a mistake somewhere but i just cannot find out where it is . I havep laced the hidden values inside the form tags.

[code]<? include("protect.php"); ?>
<? ini_set('error_reporting', E_ALL); ?>


<font face="Tahoma" size="2" color="#800080">
<html>

<head>
<script language=JavaScript>


function reload(form)
{
var val=form.ag.options[form.ag.options.selectedIndex].value;
self.location='add_new_product1.php?uid=<? echo $uid ?>&cid=<? echo $cid ?>&ag=' + val;

}

</script>

</head>



<div align="center">
    <table>

  <p align="center"><font color="#3366FF" face="Tahoma"><strong>Form
  to add an product</strong></font></p>


<?php
$cid = $_POST["choice"];
//echo $cid;

mysql_connect("localhost", $dbname, $dbpasswd )
        or die ("Unable to connect to server.");

mysql_select_db($database)
        or die ("Unable to select database.");

$sqlx="SELECT * FROM `Customers` WHERE `Customerid`= '$cid'";
//echo $sqlx;
$resultx = mysql_query($sqlx) or die (mysql_error());
$myrowx = mysql_fetch_array($resultx);


?>



  <table border="1" width="50%">
      <tr>
          <td align="center" width="5%"><font color="#3366FF" face="Tahoma" size="2"><strong> UID</strong></font></td>
          <td align="center" width="20%"><font color="#3366FF"
          face="Tahoma"size="2"><strong>Company</strong></font></td>
          <td align="center" width="15%"><font color="#3366FF"
          face="Tahoma"size="2"><strong>City</strong></font></td>
               </tr>
    <tr>
<td align="center" width="5%">
<input type=hidden name="uid"  value="<? echo $uid ?>" size="5">
<input type=text name="uid"  value="<? echo $uid ?>" disabled="true" size="5"> </td>
<td align="center" width="20%">
<input type=hidden name="customer"  value="<? echo $myrowx["Company"] ?>" size="30">
<input type=text name="customer"  value="<? echo $myrowx["Company"]?>" disabled="true" size="50" > </td>
  <td align="center" width="10%">
<input type=hidden name="city"  value="<? echo $myrowx["City"] ?>">
<input type=text name="city"  value="<? echo $myrowx["City"]?>" disabled="true"> </td>
  </td>
</tr>

  </table>
  </center></div> <p><p>


   <table border="1" width="50%" align="center">
  <tr>

  <td align="center" width="5%"><font color="#3366FF" face="Tahoma" size="2"><strong><p align="center">Category</font></td>
  <td colspan="2" width="35%"><font color="#3366FF" face="Tahoma" size="2"><strong><p align="center">Ags</font></td>
     </tr>

   <tr>

  <td align="center" width="5%"><select name="category">
<option value="">[Select One]
<option value="A">A:
<option value="B">B:
<option value="C">C:
<option value="D">D:
</select></td>

<td colspan="2" width="35%">
<?


///////// Getting the data from Mysql table for first list box//////////
$sqla = "SELECT DISTINCT `Name`,`Agid` FROM `Ags_hb` WHERE `uid`='$uid' ORDER BY `Name` asc";
//echo $sqla;

$resulta=mysql_query($sqla) or die (mysql_error());

if(isset($_GET['ag']))
{
    $cat=$_GET['ag'];
}
//echo $ag;

if(isset($ag) and strlen($ag) > 0){

$sqlb = "SELECT DISTINCT `Model` FROM `All_Products` WHERE `Agid`= $ag  ORDER BY `Model` asc";

//echo $sqlb;
$resultb=mysql_query($sqlb) or die (mysql_error());


$sqlc = "SELECT DISTINCT `Specs` FROM `All_Products` WHERE `Agid`= $ag  ORDER BY `Specs` asc";

//echo $sqlb;
$resultc=mysql_query($sqlc) or die (mysql_error());


}
else{
$resultb=mysql_query("SELECT DISTINCT `Model` FROM `All_Products` ORDER BY `Model` asc");

$resultc=mysql_query("SELECT DISTINCT `Specs` FROM `All_Products` ORDER BY `Specs` asc");
}



echo "<form method=post action='add_new_product2.php?uid=<? echo $uid ?>&cid=<? echo $cid ?>'>";
// the value of cid doesnt get into the above form action. Also, on the form gets reloaded, allthe values disappear.

echo '<input name="cid" type="hidden" value="cid">';
echo '<input name="city" type="hidden" value="<? echo $myrowx["City"]?>">';
echo '<input name="customer" type="hidden" value="<? echo $myrowx["Company"]?>">';

echo "<select name='ag' onchange=\"reload(this.form)\"><option value=''>Select one</option>";


echo '<input name="cid" type="hidden" value="cid">';
echo '<input name="city" type="hidden" value="<? echo $myrowx["City"]?>">';
echo '<input name="customer" type="hidden" value="<? echo $myrowx["Company"]?>">';

while($myrowa = mysql_fetch_array($resulta)) {
if($myrowa['Agid']==@$ag)
{
echo "<option selected value='$myrowa[Agid]'>$myrowa[Name]</option>"."<BR>";}
else
{echo  "<option value='$myrowa[Agid]'>$myrowa[Name]</option>";}
}
echo "</select>";


?></td>


</tr>

<tr>
        <td></td>
        <td></td>
        <td>Model:
        <?
     echo "<select name='model'><option value=''>Select one</option>";
while($myrowb = mysql_fetch_array($resultb)) {
echo  "<option value='$myrowb[Model]'>$myrowb[Model]</option>";
}
echo "</select>";
?>

            </td>
        <td>Specs

        <?
     echo "<select name='specs'><option value=''>Select one</option>";
while($myrowc = mysql_fetch_array($resultc)) {
echo  "<option value='$myrowc[Specs]'>$myrowc[Specs]</option>";
}
echo "</select>";



?>


    </tr>
  </table>  </div> <p><p>


    <table border="1" width="80%" align="center">
  <tr>
  <td width="90%" align="center"><font color="#3366FF" face="Tahoma" size="2"><strong><p align="center">Action</font>  </td>
  </tr>
  <tr><td width="90%" align="center">
   <textarea name="action" rows="7" cols="90"></textarea></td></tr>
  </table>
  </center></div> <p><p>




  <table border="1" cellspacing="1" width="100%" bgcolor="#0000FF">
  <tr>
          <td width="50%" bgcolor="#3366FF"><p align="center"><font
          color="#FFFFFF" size="2" face="Tahoma">Please click this button just
          once to avoid any errors. <input type="submit" value="Submit"></font></p>
          </td>
      </tr>
  </table>




//The foll. hidden values work when page is first loaded but when its reloaded for dropdown selection, it returns blank values , except for uid.

<input type="hidden" name="cid" value="<? echo $cid ?>">
<input type="hidden" name="uid" value="<? echo $uid ?>">
<input type="hidden" name="customer" value="<? echo $myrowx["Company"] ?>">
<input type="hidden" name="city" value="<? echo $myrowx["City"]?>">


  </form>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.