Need help to solve a form.....and sql..............

Discussion in 'PHP' started by mohsin45, Dec 23, 2011.

  1. #1
    (i m weak in english, pls, forgive me for language mistake)
    i am learning php for handling sql database...... i got this problem... pls, help me to solve this php code...

    In my html page, generating field in form when a button is click and send those data when submite button is clicked....

    In php page.-- quaring it from sql databse, if it is availabe, calculate the total.....

    here is my form page.......
    
    <form action="pro_price3.php" method="post">
           <div id='row1'>
        pro_id: <input type="varchar" name ="pro_id" /> | <a href='#'                         onclick="insertElementAfter(document.createElement('input'), this);"> add another field!<a><br/>
    </div>
    
    
                                                                                                     /* need help here, i want to genarate field whithout using javascript */
    
    <script type="text/javascript">
    function insertElementAfter(newElement, targetElement) {
        var parent = targetElement.parentNode;
        if(parent.lastchild == targetElement) {
            parent.appendChild(newElement);
         } else {
            parent.insertBefore(newElement, targetElement.nextSibling);
        }
    }
    </script>
     
    
    
      <input type="submit"/>
     </form>
    PHP:
    above code are not sending data.............

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    if i wrote this form by this way, i got the answer by little,..................

    
            <form action="pro_price3.php" method="post"> 
                        pro_id[1]: <input type="varchar" name="pro_id[]" />
                        pro_id[2]: <input type="varchar" name="pro_id[]" />
                        pro_id[3]: <input type="varchar" name="pro_id[]" />
                        pro_id[4]: <input type="varchar" name="pro_id[]" />
                       <input type="submit"/>
           </form>
    PHP:
    Here is php code-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    <?php
     $con = mysql_connect("localhost","root","");
     if (!$con)
       {
       die('Could not connect: ' . mysql_error());
       }
     echo "<body style = 'background-color:#700000'> ";
     
    
    
      mysql_select_db("test", $con);
    
    
          $pro_id = $_POST['pro_id'];
     
      
      
            $result = mysql_query("SELECT * FROM product_information WHERE pro_id = $pro_id[0] || pro_id = $pro_id[1] || pro_id = $pro_id[2]|| pro_id = $pro_id[3]");                  
                                             /* need help  here, creating $pro_id by looping for catching data */
          
    
    
    
    
         echo "<table border='1' width = '520' align ='center' style = 'background-color:#FFA500'>
               <tr>
               <th>pro_name</th>
               <th>pro_id</th>
               <th> price </th>
               </tr>";
    
    
                while($row = mysql_fetch_array($result))
                       {
                       echo "<tr>";
                       echo "<td>" . $row['pro_name'] . "</td>";
                       echo "<td>" . $row['pro_id'] . "</td>";
                       echo "<td>" . $row['price'] . "</td>";
                       echo "</tr>";
                        }
       
      
        
          echo "</table>";  
    
    
    $array2= mysql_query("SELECT price FROM product_information WHERE pro_id = $pro_id[0] ||  pro_id = $pro_id[1] ||  pro_id = $pro_id[2] ||  pro_id = $pro_id[3]");        
          
                  $result3 = 0;
                  while($result2 = mysql_fetch_array($array2))
                                 {
                       
                                      for ($i = 0; $i < 1; $i++) 
                                          {
                              
                                             $result3 += $result2[$i];
         
                                          }
                       
                           }             
                    
    
    
               echo "<table border='1' width = '150' align ='center' style = 'background-color:#FFA500'> ";
                            
                                 
                                 echo "<tr>";
                                 echo "<td>" . " Total price is = " . $result3 . "</td>";
                                 echo "</tr>";
                          
                         echo "</table>";  
            
      
    echo "</body>"; 
    
    
      ?>
    PHP:




    Main goal is to count the total price. In the database test, there is a three table namely pro_id(varchar,primary key) , pro_name(varchar), price(float). I want to count total price. i got the result. but i want to generate a field of same data type in same form when a button or anything is clicked. and when submit button is click,.......
     
    Last edited: Dec 25, 2011
    mohsin45, Dec 23, 2011 IP
  2. mohsin45

    mohsin45 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    someone pls, help me..... i want to generate a field of same data type in same form when a button or anything is clicked. and when submit button is click,action are worked....
     
    mohsin45, Dec 25, 2011 IP
  3. sharadcool

    sharadcool Greenhorn

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    Hello mohsin
    can i know which place u save the data .first you have save data and the count amount.I thinks you should use <input type='text' name='pro_id[]' value='12'> in one onces u did not the same name in the all text
     
    sharadcool, Dec 26, 2011 IP
  4. mohsin45

    mohsin45 Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks too many for ur replay...
    i don't want to use the value, i want to use same data type multiple field in form, so that i can put the multiple value. because, i have a lots of data in my database.i want to inherit some of data, and calculate the total....

    suppose , this is my databse....



    pro_name --- pro_id --- price

    milk ---- 01 --- 30.00
    rice--- 02 --- 20.6
    chips --- 03 --- 10.01
    pen --- 04 --- 13.01
    cap --- 05 --- 50.50
    bag --- 06 --- 100.00
    chocolate --- 07 --- 5.00
    glass --- 08 --- 200.00
    ..... --- .. --- ........
    ..... --- .. --- .........
    ..... --- .. --- .........


    if i enter the pro_id value = 02 ,03,05 ,07 in the form, it send those value to the php page, and it calculate the total and output will be (20.1 + 10.01+50.50 +5.00) = 85.61$

    i want to generate a same data type multiple field in form, so that i can enter pro_id value as many as i want....
    pls, need help for this......
     
    mohsin45, Dec 28, 2011 IP