Jump to content


Photo

Do i use a form or is it a subform ?


  • Please log in to reply
7 replies to this topic

#1 swatisonee

swatisonee
  • Members
  • PipPipPip
  • Advanced Member
  • 253 posts

Posted 25 March 2006 - 02:33 PM

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


<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>
}

Shishya

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 25 March 2006 - 03:48 PM



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

{

For a start, the code isn't inside <?php .. ?> tags so won't be processed
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 swatisonee

swatisonee
  • Members
  • PipPipPip
  • Advanced Member
  • 253 posts

Posted 27 March 2006 - 03:54 PM

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!):

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

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)

<? 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>

Shishya

#4 swatisonee

swatisonee
  • Members
  • PipPipPip
  • Advanced Member
  • 253 posts

Posted 30 March 2006 - 01:13 PM

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) View Post[/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!):

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

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)

<? 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>
[/quote]

Shishya

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 30 March 2006 - 05:39 PM

Have you thought of using xmlhttp. [a href=\"http://members.aol.com/barryaandrew/xmlhttp/article.html\" target=\"_blank\"]Sample app here[/a]
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 swatisonee

swatisonee
  • Members
  • PipPipPip
  • Advanced Member
  • 253 posts

Posted 31 March 2006 - 11:47 AM

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...

<?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 ?>">







Shishya

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 31 March 2006 - 11:54 AM

Like other form elements, hidden input fields also need to be inside the <form>..</form> tags
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 swatisonee

swatisonee
  • Members
  • PipPipPip
  • Advanced Member
  • 253 posts

Posted 01 April 2006 - 03:51 AM

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.

<? 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>

Shishya




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users