#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Ireland
    Posts
    20
    Rep Power
    0

    Smile Using form value as select query where value


    Hi,
    I have this tabbed form for inserting a new product into the database, the top two boxes, product name and code, supply the product code to all the forms on each tab so that the product can be inserted. however on two of the tabs (such as on prices) there is a section to display values as added to database. My question is how can i make the select query look up the value from the product_code box and display the values on the page? at the moment as you can see i have the product_code hard coded to test it.

    the insert query on the same page picks up the product code.

    any help much appreciated.

    thanks

    MsKazza

    add product page
    PHP Code:
    <h2>Add Product</h2>
                
                <form id="code" name="code" method="post" action="">
    Product Name :
      <input type="text" name="product_name" id="product_name" size="40" onKeyUp="sync1()"/>
    Product Code : 
      <input type="text" name="code" id="code" onKeyUp="sync()"/>

    </form><br />
                <div class="clear"></div> <!-- End .clear -->
                
                <div class="content-box"><!-- Start Content Box -->
                    
                    <div class="content-box-header">
                        
                        <h3>Content box</h3>
                        
                        <ul class="content-box-tabs">
                            <li><a href="#tab1" class="default-tab">Basic Information</a></li> <!-- href must be unique and match the id of target div -->
                            <li><a href="#tab2">Prices</a></li>
                            <li><a href="#tab3">Images</a></li>
                            <li><a href="#tab4">Options</a></li>
                        </ul>
                        
                        <div class="clear"></div>
                        
                    </div> <!-- End .content-box-header -->
                    
                    <div class="content-box-content">
                        
                        <div class="tab-content default-tab" id="tab1"> <!-- This is the target div. id must match the href of this div's tab -->
                            
                            <form id="basic" name="basic" method="post" action="">
    <table width="100%" border="0" cellspacing="4" cellpadding="4">
            <tr>
      
            
              <td>Category</td>
              <td><select name="category" class="category">
    <option selected="selected">--Select Category--</option>
    <?php
    $con
    =mysqli_connect("localhost","root","","adlantic");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo 
    "Failed to connect to MySQL: " mysqli_connect_error();
      }

    $result mysqli_query($con,"select id,cat_name from categories where display='Y'");
    while(
    $row mysqli_fetch_array($result))
    {
    $id=$row['id'];
    $data=$row['cat_name'];
    echo 
    '<option value="'.$id.'">'.$data.'</option>';
    ?>
    </select>       </td>
              <td>Sub Category</td>
              <td><select name="sub_category" class="sub_category">
    <option selected="selected">--Select Subcategory--</option>
    </select>          </td>
            </tr>
            <tr>
              <td>Supplier</td>
              <td>
               <select name="supplier"><?php 
              $resul1 
    mysqli_query($con,"SELECT * FROM supplier");
    while(
    $row1 mysqli_fetch_array($resul1))
      {
     
    ?>    <option value="<?php echo $row1['supplier_name']; ?>"> <?php echo $row1['supplier_name']; ?></option>
        <?php }  ?>     
        </td>
                  <td>Supplier Code</td>
                  <td><input type="text" name="supplier_product_code" id="supplier_product_code" /></td>
            </tr>
            <tr>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
            </tr>
          </table></p>
          
                Product Descriptions<br />
                  <br />
                  <table width="90%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="22%"></td>
                      <td width="12%"></td>
                      <td width="26%"></td>
                      <td width="40%"></td>
                    </tr>
                    <tr>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                    </tr>
                    <tr>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                    </tr>
                    <tr>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                    </tr>
                    <tr>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                    </tr>

                  </table>
          
          
          Choose your display options here:<br />
                  <br />
                  <table width="90%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="22%">Active</td>
                      <td width="12%"><input type="checkbox" name="product_active" id="product_active" /></td>
                      <td width="26%">Special Offer</td>
                      <td width="40%"><input type="checkbox" name="product_special" id="product_special" /></td>
                    </tr>
                    <tr>
                      <td>Publish</td>
                      <td><input type="checkbox" name="product_publish" id="product_publish" /></td>
                      <td>Special Offer Discount</td>
                      <td><input type="text" name="product_special_price" id="product_special_price" /></td>
                    </tr>
                    <tr>
                      <td>Display Frontpage</td>
                      <td><input type="checkbox" name="product_display_frontpage" id="product_display_frontpage" /></td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td>Display Facebook</td>
                      <td><input type="checkbox" name="display_facebook" id="display_facebook" /></td>
                      <td><strong>Margins</strong></td>
                      <td></td>
                    </tr>
                    <tr>
                      <td></td>
                      <td></td>
                      <td>Margin Group : </td>
                      <td><select name="margin_group"><?php 
              $resul2 
    mysqli_query($con,"SELECT * FROM margins");
    while(
    $row2 mysqli_fetch_array($resul2))
      {
     
    ?>    <option value="<?php echo $row2['margin_group']; ?>"> <?php echo $row2['margin_group']; ?></option>
        <?php }  ?>  </td>
                    </tr>
                    <tr>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                    </tr>
                    <tr>
                      <td><input name="product_name" type="hidden" id="product_name" size="60" />
                      <input name="product_code" type="hidden" id="product_code" /></td>
                      <td></td>
                      <td></td>
                      <td></td>
                    </tr>

                  </table><input class="button" name="submit" type="button" value="submit" />
                  
                  </form>
                  
                  
                            
                        </div> <!-- End #tab1 -->
                        
                        <div class="tab-content" id="tab2">
                        
                            <form id="pricing" name="pricing">
                   <table>
                   <tr>
                   <td>Product Quantity : <input type="text" name="product_qty" id="product_qty"/></td>
                   <td>Product Price : <input type="text" name="product_price" id="product_price"/></td><td>               
                    <input name="product_code" type="hidden"  id="product_code"/>
                   <input type="button" value="Add Price!" id="button">
                    </td></tr></table>
                   <div id="info" />
                   <ul id="comment"></ul>
            </form>
                            
                        </div> <!-- End #tab2 -->        
                        
                        
                           <div class="tab-content" id="tab3">
                        
                            tab three info
                            
                        </div> <!-- End #tab3 -->        

                       <div class="tab-content" id="tab4">
                        
                            tab four info
                            
                        </div> <!-- End #tab4 -->        
        
                        
                    </div> <!-- End .content-box-content -->
                    
                </div> <!-- End .content-box -->
                
                
                <div class="clear"></div>

    priceprocess.php

    PHP Code:
    <?php
      mysql_connect
    ("localhost","root","");
      
    mysql_select_db("adlantic");
     
     
      
    $action=$_POST["action"];
     
      if(
    $action=="showcomment"){
         
    $show=mysql_query("Select * from prices WHERE product_code = '12345'");
    echo 
    "<table><tr><td width=\"100\">Product Code</td><td width=\"100\">Quantity</td><td width=\"80\">Price</td><td></td></tr>";
         while(
    $row=mysql_fetch_array($show)){
            echo 
    "<tr><td><b>$row[product_code]</b></td> <td> $row[product_qty] </td><td> $row[product_price]</td><td><a href=\"#\" title=\"Edit\"><img src=\"resources/images/icons/pencil.png\" alt=\"Edit\" /></a>
                                             <a href=\"#\" title=\"Delete\"><img src=\"resources/images/icons/cross.png\" alt=\"Delete\" /></a> </td></tr>"
    ;
         }echo 
    "</table>";
      }
      else if(
    $action=="addcomment"){
        
    $product_code=$_POST["product_code"];
        
    $product_qty=$_POST["product_qty"];
        
    $product_price=$_POST["product_price"];
     
         
    $query=mysql_query("INSERT INTO prices(product_code,product_qty,product_price) values('$product_code','$product_qty','$product_price') ");
     
         if(
    $query){
            echo 
    "Your price has been inserted";
         }
         else{
            echo 
    "Error in sending your price";
         }
      }
    ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    189
    Rep Power
    0
    What is a tabbed form in html?

    Are you saying you have a tabbed browser?


    Anyway - to pick up a product code from one form you have to have stored it (hidden?) in the other form in order for that form's submit to provide it to your script. Sounds like you are having the user select a product in one form, then sending them to another form (another tab) to do some other work with that product and then want to handle all of it in a third form. You would have to store the selected info from the first form into the second form so that it is aware of it.

    Hope I understood you correctly. If not, my apologies.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Location
    Ireland
    Posts
    20
    Rep Power
    0
    no, the page i have (as per the code i included in post) has tabs on the page with a different form on each tab, before the start of the tabs, the user inserts the product name and product code. i have this product code copying to the other forms using
    onKeyUp="sync()" and this works perfectly. on the form that i want to use the product_code as part of the query i already have an insert statement that uses this product code and works perfectly. my problem is that i want to use this same product code on a select query such as "SELECT * FROM products WHERE product_code = $_POST[product_code]"

    the problem is that the product_code is inserted on the page and there is no submit to refresh the page. at the moment i am using ajax to show the results of the insert query but have the product_code hard coded i.e. "SELECT * FROM products WHERE product_code = 12345"

    how can i use $_POST[product_code] in ajax to make this work.

    -------edit - an afterthought -------

    is there a way that when the user submits (inserts) the form from the first tab that the post information from that could be used in the query? how long does the post information last?
    Last edited by MsKazza; July 12th, 2013 at 03:43 AM. Reason: an afterthought
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    189
    Rep Power
    0
    Use a GET for your Ajax call.

IMN logo majestic logo threadwatch logo seochat tools logo