Jump to content

Getting value from a list of drop down menu..


joinx

Recommended Posts

Here is my drop down list. I want to retrieve the values and store in a database. which will thn be used to retrive data from another table..right now the data are not being saved in the database so i'm not able to display the prices.

 

configure:

<?php require_once('../Connections/JaceyConn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "config")) {
  $insertSQL = sprintf("INSERT INTO configure (motherboard, memory, graphic, sound, modem, dvd, casing, monitor, keyboard, speaker, mouse) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['Motherboard'], "int"),
                       GetSQLValueString($_POST['Memory'], "int"),
                       GetSQLValueString($_POST['Graphic'], "int"),
                       GetSQLValueString($_POST['Sound'], "int"),
                       GetSQLValueString($_POST['Modem'], "int"),
                       GetSQLValueString($_POST['DRIVE'], "int"),
                       GetSQLValueString($_POST['Casing'], "int"),
                       GetSQLValueString($_POST['Monitor'], "int"),
                       GetSQLValueString($_POST['KEY'], "int"),
                       GetSQLValueString($_POST['Speaker'], "int"),
                       GetSQLValueString($_POST['Mouse'], "int"));

  mysql_select_db($database_JaceyConn, $JaceyConn);
  $Result1 = mysql_query($insertSQL, $JaceyConn) or die(mysql_error());

  $insertGoTo = "price.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="description" content="description"/>
<meta name="keywords" content="keywords"/> 
<meta name="author" content="author"/> 
<link rel="stylesheet" type="text/css" href="bntemplate590/images590/default.css"/>
<title>Jacey</title>
<style type="text/css">
<!--
body,td,th {
font-size: 9pt;
}
-->
/* Tabs Menu */

    #tabsE {
      float:left;
      width:100%;
      font-size:70%;
      line-height:normal;

      }
    #tabsE ul {
margin:0;
padding:10px 10px 0 50px;
list-style:none;
      }
    #tabsE li {
      display:inline;
      margin:0;
      padding:0;
      }
    #tabsE a {
      float:left;
      background:url(../Tab/tableftE.gif) no-repeat left top;
      margin:0;
      padding:0 0 0 4px;
      text-decoration:none;
      }
    #tabsE a span {
float:left;
display:block;
padding:5px 15px 4px 6px;
color:#FFF;
background-image: url(../Tab/tabrightE.gif);
background-repeat: no-repeat;
background-position: right top;
      }
    /* Commented Backslash Hack hides rule from IE5-Mac \*/
    #tabsE a span {float:none;}
    /* End IE5-Mac hack */
    #tabsE a:hover span {
      color:#FFF;
      }
    #tabsE a:hover {
      background-position:0% -42px;
      }
    #tabsE a:hover span {
      background-position:100% -42px;
      }  

.style1 {font-size: 10pt}
.style3 {font-size: 12px}
</style>
</head>


<body>

<div class="main">

<div class="main_left">

<div class="header">
		<h1 align="center">Jacey Computers</h1>
  </div>

	<div class="link_menu">
		<a href="main.php" accesskey="1">Home</a>
		<a href="category.php" accesskey="2">Product</a>
		<a href="support.php" accesskey="3">Support & Help</a>
		<a href="contact.php" accesskey="4">Contact Us</a>	
   	  </div>

  <div class="content">
        <p align="center"><strong><em>Customize your own Desktop.</em></strong></p>
        <p class="style1"> Windows XP Home is installed and 1 year guarantee is provided for any customization. To check out the details about the spare parts and their prices please visit the PC Parts section <a href="category.php">here</a>.</p>
        <form name="config" action="<?php echo $editFormAction; ?>" method="POST">
        <table width="414" border="2" cellspacing="2" cellpadding="2">
          <tr>
      <th width="393" height="33" scope="row">
        <div align="left"><strong>MOTHERBOARD :
            <select name='Motherboard'>
              <option value="68">INTEL CORE 2 DUO</option>
              <option value="69">INTEL CENTRINO DUO</option>
              <option value="70">AMD TURION 64</option>
                </select>
                </strong></div></th>
          </tr>
          <tr>
            <th height="35" scope="row"><div align="left">MEMORY:
                <select name='Memory'>
                  <option value="65">KINGSTON 512 SDRAM</option>
                  <option value="66">KINGSTON 1 GB DDRRAM</option>
                  <option value="67">KINGSTON 2 GB DDRRAM</option>
                    </select>
            </div></th>
          </tr>
          <tr>
            <th height="32" scope="row"><div align="left">GRAPHIC CARD:
                <select name='Graphic'>
                  <option value="71">POWER COLOR RADEON X1550</option>
                  <option value="72">GE FORCE 7300 VIDEO CARD</option>
                  <option value="74">GE FORCE 7000 GRAPHIC CARD</option>
                  <option value="73">MATROX GRAPHIC CARD</option>
                    </select>
            </div></th>
          </tr>
          <tr>
            <th height="33" scope="row"><div align="left">SOUND CARD:
                <select name='Sound'>
                  <option value="75">DIGITAL SOUND CARD</option>
                  <option value="76">DIAMOND MULTIMEDIA SOUND</option>
                  <option value="77">PCI 5.1 SOUND CARD</option>
                  </select>
            </div></th>
          </tr>
          <tr>
            <th height="36" scope="row"><div align="left">MODEM:
                <select name='Modem'>
                  <option value="86">INTEGRATED 56K PCI MODEM & FAX</option>
                  <option value="85">INTERNAL WINDOWS 56K MODEM</option>
                  <option value="83">LINKSYS EXTERNAL MODEM</option>
                  <option value="84">DLINK EXTERNAL MODEM</option> 
                </select>
            </div></th>
          </tr>
          <tr>
            <th height="34" scope="row"><div align="left">DVD DRIVE:
                <select name='DRIVE'>
                  <option value="87">SONY DVD DRX S70</option>
                  <option value="89">SONY DRU 180A</option> 
                  <option value="88">HP DVD WRITER 940i</option>
                  <option value="90">TOSHIBA ULTRA SLIM DVD</option>                
                    </select>
            </div></th>
          </tr>
          <tr>
            <th height="35" scope="row"><div align="left">EXTERNAL CASING:
                <select name='Casing'>
                  <option value="78">CASING 1</option>
                  <option value="79">CASING 2</option>
                  <option value="80">CASING 3</option>
                  <option value="81">CASING 4</option>
                  <option value="82">CASING 5</option>
                    </select>
            </div></th>
          </tr>
          <tr>
            <th height="35" scope="row"><div align="left">MONITOR:
                <select name='Monitor'>
                  <option value="62">VIEWSONIC LCD MONITOR 28'</option>
                  <option value="63">VIEUSONIC LCD MONITOR 22'</option>
                  <option value="64">VIEWSONIC LCD MONITOR 17'</option>
                    </select>
            </div></th>
          </tr>
          <tr>
            <th height="45" scope="row"><div align="left">KEYBOARD:
                <select name='KEY'>
                  <option value="50">LOGITECT INTERNET</option>
                  <option value="52">LOGITECT EASY </option>
                  <option value="53">LOGITECT NAVIGATOR</option>
                  <option value="54">LOGITECT GAMING</option>
                  <option value="51">LOGITECT STANDARD</option>
                    </select>
            </div></th><td width="6"></th>
          </tr>
          <tr>
            
            <th height="46" scope="row"><div align="left">MOUSE:
                <select name='Mouse'>
                  <option value="49">LOGITECT V220 OPTICAL MOUSE</option>
                  <option value="46">LOGITECT V320 LASER CORDLESS MOUSE </option>
                  <option value="45">LOGITECT V470 LASER CORDLESS MOUSE</option>
                  <option value="48">LOGITECT MX518 CORDLESS MOUSE</option>
                  <option value="47">LOGITECT G9 GAMING MOUSE</option>
                    </select>
            </div></th>
          </tr>
          <tr>
            <th height="41" scope="row"><div align="left">SPEAKERS:
                <select name='Speaker'>
                  <option value="58">LOGITECT SURROUND SYSTEM</option>
                  <option value="59">LOGITECT R20 SIMPLE SPEAKER</option>
                  <option value="60">LOGITECT Z4</option>
                </select>
            </div></th>
          </tr>
          </table> 
          		  
              <p><input type="submit" name="button" id="button" value="Calculate Price" />
              </p>
            
            
              <input type="hidden" name="MM_insert" value="config" />
        </form>
      </div>
       



</div>
<div class="footer">
  <div align="center">© www.jacey.mu </div>
</div>
</div>
<br style="clear: both;" />

</body>

</html>



 

and my price.php

<?php require_once('../Connections/JaceyConn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_JaceyConn, $JaceyConn);
$query_id = "SELECT * FROM configure";
$id = mysql_query($query_id, $JaceyConn) or die(mysql_error());
$row_id = mysql_fetch_assoc($id);
$totalRows_id = mysql_num_rows($id);




?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="description" content="description"/>
<meta name="keywords" content="keywords"/> 
<meta name="author" content="author"/> 
<link rel="stylesheet" type="text/css" href="bntemplate590/images590/default.css"/>
<title>Jacey</title>
<style type="text/css">
<!--
.style4 {font-size: 14pt}
body,td,th {
font-size: 9pt;
}
-->
</style></head>

<body>

<div class="main">

<div class="main_left">

<div class="header">
		<h1 align="center">Jacey Computers</h1>
  </div>

	<div class="link_menu">
		<a href="main.php" accesskey="1">Home</a>
		<a href="category.php" accesskey="2">Product</a>
		<a href="support.php" accesskey="3">Support & Help</a>
		<a href="contact.php" accesskey="4">Contact Us</a>		</div>

	<div class="content">
   
	<table align="center" border="2">
         <?php

	 $totalRows_id = mysql_num_rows($id);
	 $row = mysql_fetch_array($id);
	 $total=0;

	 for($x=1; $x < $totalRows_id; $x++)
	 {
	 	$id=$row[x];
		echo $id;
		mysql_select_db($database_JaceyConn, $JaceyConn);
		$query_price = "SELECT Product_name, product_price FROM product where product_id = '$id'; ";
		$price = mysql_query($query_price, $JaceyConn) or die(mysql_error());
		$row_price = mysql_fetch_assoc($price);
		while($row2 = mysql_fetch_array($price)) {?>         
            <tr>
            <td>Product Name:<?php $row2['Product_name'];?></td>
            </tr>
            <tr>
		<td> Price:<?php $row2['product_price'];?></td> 
            </tr>
            <?php }
            $total= $total+$row2['product_price'];
		}?>
		<tr>
            <td>Total Price:<?php echo $total;?></td>
            </tr>
            </table>  		

  <form id="form1" method="get" action="showcart.php">
		  <p>
		    <input type="submit" name="button" id="button" value="Add To Cart" />
		  </p>
		  <p><a href="configure.php">Go back</a> to previous page </p>
		</form>


</div>
</div>

<div class="footer"></div>
</div>
<br style="clear: both;" />

</body>

</html>


Well, I don't understand what your problem is. Do you know how to use $_POST to get the data from the HTML forms when they are submitted? Try adding var_dump($_POST); to your page that recieves the form data and you can see what data you have to work with.

 

Here is the basic way to do it:

<?php

if (isset($_POST['name_of_submit_button']))
{
  // Clean up var1
  $var1 = trim($_POST['var1']);
  // Now $var1 can be used in your code.
}
?>

ok i'll be more clear..

i have made several drop down list..once the user select all of them..this should be inserted in the database..

this is my problem...all the data in the drop down list has a value...this integer value should be inserted in the table...

 

OK now its being saved in the database...

but not calculating the price...

i have to work with 2 tables..i created to recordset..

 

<?php require_once('../Connections/JaceyConn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_JaceyConn, $JaceyConn);
$query_id = "SELECT * FROM configure";
$id = mysql_query($query_id, $JaceyConn) or die(mysql_error());
$row_id = mysql_fetch_assoc($id);
$totalRows_id = mysql_num_rows($id);




?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="description" content="description"/>
<meta name="keywords" content="keywords"/> 
<meta name="author" content="author"/> 
<link rel="stylesheet" type="text/css" href="bntemplate590/images590/default.css"/>
<title>Jacey</title>
<style type="text/css">
<!--
.style4 {font-size: 14pt}
body,td,th {
font-size: 9pt;
}
-->
</style></head>

<body>

<div class="main">

<div class="main_left">

<div class="header">
		<h1 align="center">Jacey Computers</h1>
  </div>

	<div class="link_menu">
		<a href="main.php" accesskey="1">Home</a>
		<a href="category.php" accesskey="2">Product</a>
		<a href="support.php" accesskey="3">Support & Help</a>
		<a href="contact.php" accesskey="4">Contact Us</a>		</div>

	<div class="content">
   
	<table align="center" border="2">
         <?php

	 $totalRows_id = mysql_num_rows($id);
	 $row = mysql_fetch_array($id);
	 $total=0;

	 for($x=1; $x < $totalRows_id; $x++)
	 {
	 	$id=$row[x];
		echo $id;
		mysql_select_db($database_JaceyConn, $JaceyConn);
		$query_price = "SELECT Product_name, product_price FROM product where product_id = '$id'; ";
		$price = mysql_query($query_price, $JaceyConn) or die(mysql_error());
		$row_price = mysql_fetch_assoc($price);
		while($row2 = mysql_fetch_array($price)) {?>         
            <tr>
            <td>Product Name:<?php $row2['Product_name'];?></td>
            </tr>
            <tr>
		<td> Price:<?php $row2['product_price'];?></td> 
            </tr>
            <?php }
            $total= $total+$row2['product_price'];
		}?>
		<tr>
            <td>Total Price:<?php echo $total;?></td>
            </tr>
            </table>  		

  <form id="form1" method="get" action="showcart.php">
		  <p>
		    <input type="submit" name="button" id="button" value="Add To Cart" />
		  </p>
		  <p><a href="configure.php">Go back</a> to previous page </p>
		</form>


</div>
</div>

<div class="footer"></div>
</div>
<br style="clear: both;" />

</body>

</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.