Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Facing a problem in passing values from dropdown list to query...!!!

    Hello guyes…
    I’m new in this PHP world.
    I have tried in either ways, but it's not working for me.
    I have to play with 3 values selected by user from the dropdown list, i.e. $_POST['plotid_1'],$_POST['year1'],$_POST['year2']. I'm not able to pass these values to query.
    Here i'm posting my code :

    <?php
    session_start();
    ob_start();
    ?>
    <form name="form" id="form" method="post" action="index.php?page=report3" onsubmit="return
    validateForms('form');">

    <table width="60%" align="center" cellpadding="5" cellspacing="1" bgcolor="#CCCC99">
    <tr bgcolor="#FFFFFF">
    <td class="heading" colspan="2" align="center" bgcolor="#EEEEEE">PlotWise Yield Analysis</td>
    </tr>

    <tr bgcolor="#FFFFFF">
    <td class="graytext" align="right">Season 1 : </td>
    <td align="left"><select id="year1" name="year1">
    <?php
    $q1=mysql_query("select distinct season from seasonmaster");
    while($rs1=mysql_fetch_array($q1))
    { if($_REQUEST["yid"]==$rs1[season]){
    ?>
    <option value=" <?php echo $rs1[season];?> " selected="selected"><?php echo $rs1[season];?></option>
    <?php } else{
    ?>
    <option value="<?php echo $rs1[season];?>"><?php echo $rs1[season];?></option>
    <?php }
    } ?>
    </select>
    <span id="uname" class="rederr"></span>
    </td>
    </tr>
    <tr bgcolor="#FFFFFF">
    <td class="graytext" align="right">Season 2 : </td>
    <td align="left"><select id="year2" name="year2">
    <?php
    $q1=mysql_query("select distinct season from seasonmaster");
    while($rs1=mysql_fetch_array($q1))
    { if($_REQUEST["yid2"]==$rs1[season]){
    ?>
    <option value="<?php echo $rs1[season];?>" selected="selected"><?php echo $rs1[season];?></option>
    <?php } else{ ?>
    <option value="<?php echo $rs1[season];?>"><?php echo $rs1[season];?></option>
    <?php }
    }?>
    </select><br />
    <span id="pass" class="rederr"></span>
    </td>
    </tr>

    <tr bgcolor="#FFFFFF">
    <td class="graytext" align="right">Plot No. :</td>
    <td align="left"><select name="plotid_1" id="plotid_1">
    <option value="0">--Select Plot--</option>

    <?php
    $Sql=mysql_query("SELECT * FROM plots ");
    while($row = mysql_fetch_array($Sql))
    {
    if($_REQUEST["pid"]==$row[plotno])
    echo "<option value=$row[plotno] selected>$row[plotno]</option>"; else
    echo "<option value=$row[plotno]>$row[plotno]</option>"; }

    if($_POST['plotid_1'])
    {
    $s1=mysql_query("select 'sid' from 'seasonmaster' where 'season'='".$_POST[year1]."'");
    $rss1=mysql_fetch_array($s1);
    $sql1=mysql_query("select sum(total)from 'actual_yield' where 'tid' in (SELECT 'tid' FROM 'treemaster' WHERE 'plotid'=(select 'plotid' from 'plots' where 'plotno'='".$_POST[plotid_1]."'))and 'sid'='".$rss1[sid]."'");
    $rsAy=mysql_fetch_array($sql1);
    session_register("actY1");
    $_SESSION["actY1"]=$rsAy['total'];

    $s2=mysql_query("select 'sid' from 'seasonmaster' where 'season'='".$_POST[year2]."'");
    $rss2=mysql_fetch_array($s2);
    $sql2=mysql_query("select sum(total)from 'actual_yield' where 'tid' in (SELECT 'tid' FROM 'treemaster' WHERE 'plotid'=(select 'plotid' from 'plots' where 'plotno'='".$_POST[plotid_1]."'))and 'sid'='".$rss2[sid]."'");
    $rsAy1=mysql_fetch_array($sql2);
    session_register("actY2");
    $_SESSION["actY2"]=$rsAy1['total'];
    }

    ?>
    </select><br>
    <span id="plotid" class="rederr"></span>
    <td>
    </tr>

    <tr bgcolor="#FFFFFF">
    <td class="heading" colspan="2" align="center"><input type="submit" class="button" name="save" id="save" value=" Show "></td>
    </tr>
    </table>
    </form>

    -----------------------------------------------------------------------------------------------------------------------------------------------------Here is my code. I have to play with 3 values selected by user from the dropdown list.
    I'm doing it in this way, but it's not working.
    How can i do this....???

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    I'm doing it in this way, but it's not working.
    How can i do this....???
    Please edit your post and add [PHP][/PHP] tags around your code, to make it easier for reading.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    PHP Code:
    <?php
    session_start
    ();
    ob_start();
    ?>
    <form name="form" id="form" method="post" action="index.php?page=report3" onsubmit="return
    validateForms('form');">

    <table width="60%" align="center" cellpadding="5" cellspacing="1" bgcolor="#CCCC99">
    <tr bgcolor="#FFFFFF">
    <td class="heading" colspan="2" align="center" bgcolor="#EEEEEE">PlotWise Yield Analysis</td>
    </tr>

    <tr bgcolor="#FFFFFF">
    <td class="graytext" align="right">Season 1 : </td>
    <td align="left"><select id="year1" name="year1">

    <?php
    $q1 
    mysql_query("SELECT distinct season FROM `seasonmaster`") or die(mysql_error());
    while(
    $rs1 mysql_fetch_array($q1))

        if(
    $_REQUEST["yid"]==$rs1[season])
        {
            echo 
    "<option value=\"".$rs1[season]."\" selected=\"selected\">".$rs1[season]."</option>\n";
        } 
        else
        { 
            echo 
    "<option value=\"".$rs1[season]."\">".$rs1[season]."</option>\n"
        }

    ?>

    </select>
    <span id="uname" class="rederr"></span>
    </td>
    </tr>
    <tr bgcolor="#FFFFFF">
    <td class="graytext" align="right">Season 2 : </td>
    <td align="left">
    <select id="year2" name="year2">

    <?php
    $q1 
    mysql_query("SELECT distinct season FROM `seasonmaster`");
    while(
    $rs1 mysql_fetch_array($q1))

        if(
    $_REQUEST["yid2"]==$rs1[season])
        {
            echo 
    "<option value=\"".$rs1[season]."\" selected=\"selected\">".$rs1[season]."</option>\n";
        } 
        else
        {
            echo 
    "<option value=\"".$rs1[season];."\">".$rs1[season]."</option>\n"
        }
    }
    ?> 
    </select><br />
    <span id="pass" class="rederr"></span>
    </td>
    </tr>

    <tr bgcolor="#FFFFFF">
    <td class="graytext" align="right">Plot No. :</td>
    <td align="left"><select name="plotid_1" id="plotid_1">
    <option value="0">--Select Plot--</option>

    <?php
    $Sql 
    mysql_query("SELECT * FROM `plots`") or die(mysql_error());
    while(
    $row mysql_fetch_array($Sql))
    {
        if(
    $_REQUEST["pid"]==$row[plotno])
        {
            echo 
    "<option value=\"".$row[plotno]."\">".$row[plotno]."</option>\n"
        }
        else
        {
            echo 
    "<option value=\"".$row[plotno]."\">".$row[plotno]."</option>"
        }
    }
    if(isset(
    $_POST['year1']))
    {
        
    $postYear $_POST['year1'];
    }
    else
    {
        die(
    "you havent got a value set for year1";
    }
    if(isset(
    $_POST['plotid_1']))
    {
        
    $plotID1 $_POST['plotid_1'];
    }
    else
    {
        die(
    "you have not got a val set for plotid_1");
    }
    $rss1_ $rss1[sid];
    if(isset(
    $_POST['year2']))
    {
        
    $postYear2 $_POST['year2'];
    }
    else
    {
        die(
    "you have not got a val set for year2");
    }
    $rss2_ $rss2[sid];

    if(
    $_POST['plotid_1'])
    {
        
    $s1 mysql_query("SELECT sid FROM `seasonmaster` WHERE season = '$postYear'") or die(mysql_error());
        
    $rss1 mysql_fetch_array($s1);
        
        
    $sql1 mysql_query("SELECT sum(total) FROM `actual_yield` WHERE tid in (SELECT tid FROM `treemaster` WHERE plotid = (SELECT plotid FROM plots WHERE plotno = '$plotID1')) AND sid = '$rss1_'") or die(mysql_error());
        
    $rsAy mysql_fetch_array($sql1);
        
        
    session_register("actY1");
        
    $_SESSION["actY1"] = $rsAy['total'];

        
    $s2 mysql_query("SELECT sid FROM `seasonmaster` WHERE season = '$postYear2'");
        
    $rss2 mysql_fetch_array($s2);
        
        
    $sql2 mysql_query("SELECT sum(total) FROM `actual_yield` WHERE tid in (SELECT tid FROM `treemaster` WHERE plotid = (SELECT plotid FROM `plots` WHERE plotno = '$plotID1]')) AND sid = '$rss2_'") or die(mysql_error());
        
    $rsAy1=mysql_fetch_array($sql2);
        
        
    session_register("actY2");
        
    $_SESSION["actY2"]=$rsAy1['total'];
    }

    ?>
    </select><br>
    <span id="plotid" class="rederr"></span>
    <td>
    </tr>

    <tr bgcolor="#FFFFFF">
    <td class="heading" colspan="2" align="center"><input type="submit" class="button" name="save" id="save" value=" Show "></td>
    </tr>
    </table>
    </form>
    Last edited by Phil Jackson; 08-27-2009 at 08:48 AM.

  • #4
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    the post above has just been updated.

  • #5
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for ur precious reply...

    I have tried the solution u suggested, but it is not showing my "Show" button, so i'm unable to understand wheather this code is working properly or not. What should do in above code so that i can display "Show" button...???

  • #6
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    PHP Code:
    <?php
    session_start
    ();
    ob_start();
    ?>
    <form name="form" id="form" method="post" action="index.php?page=report3" onsubmit="return
    validateForms('form');">

    <table width="60%" align="center" cellpadding="5" cellspacing="1" bgcolor="#CCCC99">
    <tr bgcolor="#FFFFFF">
    <td class="heading" colspan="2" align="center" bgcolor="#EEEEEE">PlotWise Yield Analysis</td>
    </tr>

    <tr bgcolor="#FFFFFF">
    <td class="graytext" align="right">Season 1 : </td>
    <td align="left"><select id="year1" name="year1">

    <?php
    $con 
    mysql_connect("localhost""user""pass");
    $db mysql_select_db("dbname"$con);
                
    $q1 mysql_query("SELECT distinct season FROM `seasonmaster`") or die(mysql_error());
    while(
    $rs1 mysql_fetch_array($q1))

        if(
    $_REQUEST["yid"]==$rs1[season])
        {
            echo 
    "<option value=\"".$rs1[season]."\" selected=\"selected\">".$rs1[season]."</option>\n";
        } 
        else
        { 
            echo 
    "<option value=\"".$rs1[season]."\">".$rs1[season]."</option>\n"
        }

    ?>

    </select>
    <span id="uname" class="rederr"></span>
    </td>
    </tr>
    <tr bgcolor="#FFFFFF">
    <td class="graytext" align="right">Season 2 : </td>
    <td align="left">
    <select id="year2" name="year2">

    <?php
    $q1 
    mysql_query("SELECT distinct season FROM `seasonmaster`");
    while(
    $rs1 mysql_fetch_array($q1))

        if(
    $_REQUEST["yid2"]==$rs1[season])
        {
            echo 
    "<option value=\"".$rs1[season]."\" selected=\"selected\">".$rs1[season]."</option>\n";
        } 
        else
        {
            echo 
    "<option value=\"".$rs1[season]."\">".$rs1[season]."</option>\n"
        }
    }
    ?> 
    </select><br />
    <span id="pass" class="rederr"></span>
    </td>
    </tr>

    <tr bgcolor="#FFFFFF">
    <td class="graytext" align="right">Plot No. :</td>
    <td align="left"><select name="plotid_1" id="plotid_1">
    <option value="0">--Select Plot--</option>

    <?php
    $Sql 
    mysql_query("SELECT * FROM `plots`") or die(mysql_error());
    while(
    $row mysql_fetch_array($Sql))
    {
        if(
    $_REQUEST["pid"]==$row[plotno])
        {
            echo 
    "<option value=\"".$row[plotno]."\">".$row[plotno]."</option>\n"
        }
        else
        {
            echo 
    "<option value=\"".$row[plotno]."\">".$row[plotno]."</option>"
        }
    }
    if(isset(
    $_POST['year1']))
    {
        
    $postYear $_POST['year1'];
    }
    else
    {
        die(
    "you havent got a value set for year1");
    }
    if(isset(
    $_POST['plotid_1']))
    {
        
    $plotID1 $_POST['plotid_1'];
    }
    else
    {
        die(
    "you have not got a val set for plotid_1");
    }
    $rss1_ $rss1[sid];
    if(isset(
    $_POST['year2']))
    {
        
    $postYear2 $_POST['year2'];
    }
    else
    {
        die(
    "you have not got a val set for year2");
    }
    $rss2_ $rss2[sid];

    if(
    $_POST['plotid_1'])
    {
        
    $s1 mysql_query("SELECT sid FROM `seasonmaster` WHERE season = '$postYear'") or die(mysql_error());
        
    $rss1 mysql_fetch_array($s1);
        
        
    $sql1 mysql_query("SELECT sum(total) FROM `actual_yield` WHERE tid in (SELECT tid FROM `treemaster` WHERE plotid = (SELECT plotid FROM plots WHERE plotno = '$plotID1')) AND sid = '$rss1_'") or die(mysql_error());
        
    $rsAy mysql_fetch_array($sql1);
        
        
    session_register("actY1");
        
    $_SESSION["actY1"] = $rsAy['total'];

        
    $s2 mysql_query("SELECT sid FROM `seasonmaster` WHERE season = '$postYear2'");
        
    $rss2 mysql_fetch_array($s2);
        
        
    $sql2 mysql_query("SELECT sum(total) FROM `actual_yield` WHERE tid in (SELECT tid FROM `treemaster` WHERE plotid = (SELECT plotid FROM `plots` WHERE plotno = '$plotID1]')) AND sid = '$rss2_'") or die(mysql_error());
        
    $rsAy1=mysql_fetch_array($sql2);
        
        
    session_register("actY2");
        
    $_SESSION["actY2"]=$rsAy1['total'];
    }

    ?>
    </select><br>
    <span id="plotid" class="rederr"></span>
    <td>
    </tr>

    <tr bgcolor="#FFFFFF">
    <td class="heading" colspan="2" align="center"><input type="submit" class="button" name="save" id="save" value=" Show "></td>
    </tr>
    </table>
    </form>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •