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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    413
    Thanks
    17
    Thanked 2 Times in 2 Posts

    2nd var won't pass to php query

    gah! Just when I thought I had this script done, I run into another issue.

    I can't seem to pass a variable from the second dropdown, so that it puts it in the database. The query works just fine. The dropdown populates just fine. But somehow the id of the second dropdown isn't going to the query. I have the plant_id passed from a previous page and added as a hidden field. I just need that subcat id..


    PHP Code:



    <?php 

    if (isset($_POST['submit'])){

    require (
    'db.php');

        
    $pi mysql_real_escape_string($_POST['plant_id']);
        
    $term mysql_real_escape_string($_POST['subcat']);
     
    // this term variable is what I want into term id
    $query "INSERT INTO termin_connect_to_plants(plant_id, term_id) VALUES ('$pi', '$term')";
    echo 
    $query
    // deleting echo query when done with script
        
    $result mysql_query ($query);

        if (
    mysql_affected_rows() == 1) {
        echo 
    'your plant has been updated';
        }
    }
    ?>

    <!doctype html public "-//w3c//dtd html 3.2//en">

    <html>

    <head>
    <script type="text/javascript">

    function reload(form,var2)
    {
    var val=form.cat.options[form.cat.options.selectedIndex].value;
    var val2='var2';

    self.location='edit_user15.php?cat=' + val + '&id=' + val2 ;
    }

    </script>
    </head>

    <body>


    <? 
    require ('db.php');

    if ((isset(
    $_GET['id'])) && (is_numeric($_GET['id']))) {

        
    $id $_GET['id'];

    }

    @
    $cat=$_GET['cat']; 
    if(
    strlen($cat) > and !is_numeric($cat)){  
    echo 
    "Data Error";
    exit;
    }


    //@$cat=$HTTP_GET_VARS['cat']; // Use this line or above line if register_global is off


    $quer2=mysql_query("SELECT DISTINCT part,id FROM plant_parts order by part"); 


    if(isset(
    $cat) and strlen($cat) > 0){
    $quer=mysql_query("SELECT DISTINCT part,id FROM terminology where List1Ref=$cat order by part"); 
    }else{
    $quer=mysql_query("SELECT DISTINCT part FROM terminology order by part"); }
     
    // the above works. It's populating dropdowns



    echo "<br><br><form method=post name=f1 action=''>";

    echo 
    "<select name='cat' onchange=\"reload(this.form,1) \"><option value=''>Select one</option>";
    while(
    $row mysql_fetch_array($quer2)) { 
    if(
    $row[id]==@$cat){echo "<option selected value='$row[id]'>$row[part]</option>"."<BR>";}
    else{echo  
    "<option value='$row[id]'>$row[part]</option>";}
    }
    echo 
    "</select>";


    //////////        Starting of second drop downlist /////////
    echo "<select name='subcat' onchange=\"reload(this.form) \"><option value=''>Select one</option>";
    while(
    $row mysql_fetch_array($quer)) { 

    echo  
    "<option value='$row[id]'>$row[id] $row[part]</option>";

    }
    echo 
    "</select>";

    //  above id row variable is what I need to pass. I put it in the visible part of the option value to show that it is indeed pulling the data. and it is. I just can't pass it
    //////////////////  This will end the second drop down list ///////////

    echo "<input type='hidden' name='plant_id' value=".$id.">  

    <input type=submit name=submit value=submit>"
    ;
    echo 
    "</form>";

    ?>


    </body>

    </html>

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    if($row[id]
    Shouldn't' be:
    Code:
    if($row[$id]
    or
    Code:
    if($row["id"]
    ?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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