0

trying to get i form going, so that the user can just a code from a list generated from a database(i got that bit working), and then bring up a new page with the details of that product. i cant seem to get it to send the variable through

here is the page with the list on

<html>
<head>
<title>Gardens 4 U |  Purchase</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#container #mainContent h1 {
	text-align: center;
}
#container #mainContent form table {
	text-align: right;
	font-size: 12px;}
-->
</style>
</head>

<body class="thrColFixHdr">

<div id="container">
  <div id="header">
    <h1>&nbsp;</h1>
  </div>
  <div id="mainContent">
<h2>Purchase</h2>
<form action="purchaseTwo.php" method="post">
  <?php
echo "Product Code: ";
$connect=mysql_connect ('localhost','root','') or die ("could not connect");
mysql_select_db ('gfu',$connect);
$sql = "SELECT DISTINCT Product_Code FROM product_supplier";
$result = mysql_query($sql, $connect) or die("could not run");
echo"<select name = ProductCode>";
while($row=mysql_fetch_object($result))
{
echo "<option value = '".$row->Product_Code."'>$row->Product_Code</option>";

}

echo"</select>";
?>
<input type="Submit" name="continue"  value="Next Step ->">
</form>
  </div>
  <div id="footer">
    <p>Privacy | Access | Contact</p>
  </div>
</div>
</body>
</html>

the next page i want it to go to

<html>
<head>
<title>Gardens 4 U |  Purchase</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#container #mainContent h1 {
	text-align: center;
}
#container #mainContent form table {
	text-align: right;
	font-size: 12px;}
-->
</style>
</head>

<body class="thrColFixHdr">

<div id="container">
  <div id="header">
    <h1>&nbsp;</h1>
  </div>
  <div id="mainContent">
<h2>Purchase</h2>
<hr>
<?php
		$prodID = $_POST['Product_Code'];	
			
        $connect=mysql_connect ('localhost','root','') or die ("could not connect");
		mysql_select_db ('gfu',$connect);
		$sql="SELECT * FROM product_supplier WHERE product_supplier.Product_Code = '$prodID'";
		$result=mysql_query($sql, $connect) or die("Could not run query, please try again.");

		while($row=mysql_fetch_object($result))
		{
    		echo "<table>";
			echo "<tr>";
			echo "<td width='600'>";
			echo "Product Code: ";
			echo $row->Product_Code;
			echo "</td>";
			echo "</tr>";
			echo "</table>";
		}
		echo $prodID;
?>
<hr>
  </div>
  <div id="footer">
    <p>Privacy | Access | Contact</p>
  </div>
</div>
</body>
</html>
3
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by diafol
0

alright you are writing the form and you use the name as the in the next page variable what us did wrong is used this in the next page.

$prodID = $_POST['Product_Code'];

what you should of used was this in the next in the next page.

$prodID = $_POST["ProductCode"]

your only mistake was adding the underscore. also you may want to use single quotes instead of double quotes a little more often for better load time of your script also you may want to keep the script clean from unnecessary line brakes.

0
echo '<select name = "ProductCode">';

enclose attribute values within quotes (double preferrably)

$prodID = mysql_real_escape_string($_POST['ProductCode']);

You should sanitize form data before inputting to DB. Attempting to input raw data to DBs can be VERY dangerous.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.