karin21 0 Newbie Poster

hi there.. n_n i have this simple project in php where in i can select item from dropdown list and display their details in textbox.. but my problem is it display all details without selecting the item.. can anyone help me out on this.. many thanks in advance..

code:

<script type="text/javascript" language="javascript">


function reload(form){

var val=form.cat.options[form.cat.options.selectedIndex].value; 
self.location='sales.php?cat=' + val ;
	
}



</script>

<?php

$db_host = 'xxx';
$db_user = 'xxx';
$db_pass = 'xxx';
$db_db = 'xxx';

$db_link = mysql_connect($db_host, $db_user, $db_pass) or die('MySQL Connection Error:'.mysql_error());
	mysql_select_db($db_db) or die('MySQL Error: Cannot select table'); 


		
 


$quer2=mysql_query("SELECT DISTINCT pname,id FROM product order by pname");





$cat=$_GET['cat']; //This line is added to take care if your global variable is off
if(is_numeric($id)){
echo "Data Error";
exit;
					}
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT pcode,up,sellprice,pquan FROM product where id=$cat order by pcode");
}else{$quer=mysql_query("SELECT DISTINCT pcode,up,sellprice,pquan FROM product order by pcode"); }


echo "<tr><form method='post' name=f1 action=''>";


echo "<th rowspan=8><select name='cat' size=9 ondblclick=\"reload(this.form)\"><option value='0'>Select Product</option>";
while($display2 = mysql_fetch_array($quer2)) {
if($display2['id']==@$cat){echo "<option selected value='$display2[id]'>$display[pname]</option>"."";}
else{echo "<option value='$display2[id]'>$display2[pname]</option>";}
}
echo "</select>";




while($display = mysql_fetch_array($quer)) {

echo "<th><th>Product Code:<th><input type='text' value='$display[pcode]' readonly> <tr>";
echo "<th><th>Unit in Stock:<th><input type='text' name='stock' value='$display[pquan]' readonly><tr>";
echo "<th><th>Sell Price:<th><input type='text' name='sp' value='$display[sellprice]' onkeyup='return autocalc(this,quan)' readonly><tr>";
echo "<th><th>Quantity:<th><input type='text' name='quan' onkeyup='return autocalc(this,sp)' maxlength=5><tr>";

}


echo "<th><th><input type='submit' name='process' value='Process' onclick='wat()'>";
echo "<th><input type='reset' value='Clear'>";
echo "</form>";


?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.