How to use form values in mysql query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kangana
    New Member
    • Aug 2010
    • 1

    #1

    How to use form values in mysql query

    I've created one table, which displays image and its corresponding design ID. This table is surrounded by FORM tag in order to pass hidden value (i.e, design ID).

    I want to use this design ID in an another query to display some other output.

    Here's my code:

    Code:
    <html>
    <style type="text/css">
    <!--
    #design {
    	position:absolute;
    	left:182px;
    	top:32px;
    	width:766px;
    	height:568px;
    	z-index:1;
    	visibility: visible;
    }
    -->
    </style>
    <script type="text/JavaScript">
    <!--
    
    //-->
    </script>
    <body>
    <?php
        // just so we know it is broken
        error_reporting(E_ALL);
        //connect to the db
        $link = mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
         // select our database
        mysql_select_db("templetree") or die(mysql_error());
         // get the rows from the db
    	 
    	 
        $sql = "SELECT ID, design_ID FROM sample_design WHERE product_code='BA' ";
    	 // the result of the query
        $sql_result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
    ?>
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="uploadform">
     <table border="0">
    <?php
       $c=0;
       while($row = mysql_fetch_array( $sql_result )) {
    ?>
    <tr><td>
     <?php  // Print out the contents of each row into a tag
     echo '<img src="testgetpicture1.php?ID='.$row['ID'].'" width="150" height="150"/><br/>';
     ?> 
    </tr></td>
    <tr><td height="50" align="center" valign="top" ><span onClick="if(document.getElementById('design').style.display=='none') {document.getElementById('design').style.display='block';} else {document.getElementById('design').style.display='none';}" ><?php echo $row['design_ID'];?> </span></td>
    </tr>
      <input type="hidden" name="image_id[$c]" value='design_ID' ?>">
    	<?php 
    	$c++;
    ?>
    
    <?php  } ?> </table>
    </form>
    <?php  // close the db link
    mysql_close($link); 
    ?> 
    
    <div id="design" style="display: none;">
    <?php
    include "Connections/database_connect.php"; 
    
    $query = "SELECT * FROM products, sample_design, design_detail, specification, property WHERE products.product_code=sample_design.product_code AND sample_design.design_ID=design_detail.design_ID AND design_detail.spec_ID=specification.spec_ID AND design_detail.property_ID=property.property_ID AND design_detail.design_ID='design_ID'";
    $result=mysql_query($query);
    $row_result = mysql_fetch_assoc($result);
    
    $query2="SELECT * FROM property, design_detail WHERE property.property_ID=design_detail.property_ID AND design_detail.design_ID='design_ID'";
    $result2=mysql_query($query2);
    $num=mysql_numrows($result2);
    
    
    mysql_close();
    ?>
    <table width="1029" border="1" bordercolor="#FF6633" cellpadding="5" cellspacing="0">
    <tr>
      <td rowspan="13"><img src="testgetpicture.php?image_id=2" width="384" height="384" align="top" /></td>
    </tr>
    <tr>
    <th><div align="left"><font face="Arial, Helvetica, sans-serif">Product Name</font></div></th>
    <td><font face="Arial, Helvetica, sans-serif"><?php echo $row_result['product_name']; ?></font></td>
    </tr>
    <tr>
    <th><div align="left"><font face="Arial, Helvetica, sans-serif">Product Code</font></div></th>
    <td><font face="Arial, Helvetica, sans-serif"><?php echo $row_result['product_code']; ?></font></td>
    </tr>
    <tr>
    <th><div align="left"><font face="Arial, Helvetica, sans-serif">Design ID</font></div></th>
    <td><font face="Arial, Helvetica, sans-serif"><?php echo $row_result['design_ID']; ?></font></td>
    </tr>
    <tr>
    <th><div align="left"><font face="Arial, Helvetica, sans-serif">Design Description</font></div></th>
    <td><font face="Arial, Helvetica, sans-serif"><?php echo $row_result['design_description']; ?></font></td>
    </tr>
    <tr>
    <th><div align="left"><font face="Arial, Helvetica, sans-serif">Price</font></div></th>
    <td><font face="Arial, Helvetica, sans-serif">Rs. <?php echo $row_result['price']; ?></font></td>
    </tr>
    
    <?php
    $i=0;
    $f1=mysql_result($result2,$i,"property_name");
    ?>
    <tr>
      <th><div align="left"><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></div></th>
    <td><font face="Arial, Helvetica, sans-serif"><?php echo $row_result['spec_name'];?></font></td>
    </tr>
    <?php
    $i=1;
    
    while ($i < $num) {
    
    $f1=mysql_result($result2,$i,"property_name");
    $f2=mysql_result($result2,$i,"property_description");
    ?>
    
    <tr>
      <th><div align="left"><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></div></th>
    <?php
    $r=mysql_fetch_assoc($result);
    
    //echo $r['spec_name'];
    ?>
    <td><font face="Arial, Helvetica, sans-serif"><?php echo $r['spec_name'];?></font></td>
    </tr>
    
    <?php
    $i++;
    }
    ?>
    </table>
    </div>
    </body>
    </html>

    My question:
    How can I pass hidden form value to mysql quer to display output. What I've done is right or wrong?
Working...