I have a database containing records which I want to edit. I populate a list box which gets populated with the records in the database and I select and click on one of the records for editing.

I find that I am able to select the record from the listbox, but I am not able to display them in the Text Boxes for editing. While the first set of code runs with out any problem, the second set shows an error. I request members to guide me with the correct code (Code 2). My code is as under:

Suryanarayanan

Code for selecting record from a list box ( Code 1)

<HTML>
<HEAD>
<TITLE>MATERIAL SPECIFICATION</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2180" name=GENERATOR><style type="text/css">

<!--
body {
	background-color: #33FFCC;
}
.style1 {
	font-size: 18px;
	font-weight: bold;
	color: #000099;
	font-family: OptimusPrinceps, OptimusPrincepsSemiBold;
}
 
.style9 {
	font-size: x-small;
	font-weight: bold;
}
.style10 {
	font-family: Verdana;
	font-size: 12px;
	color: #000099;
}
.style34 {color: #000099; font-family: Georgia; font-weight: bold; }
 
-->
</style></HEAD>


<body>
<form action="vendor-modifn.php" method=post>
  <table width="652" height="60" align="center">
  <tr>
    <td width="644" height="60" align="center" valign="top"><h1>
</CENTER>        
<u>VENDOR MASTER DATA EDIT MENU</u>
        </h1>
         <h1>
            <h1>
              <h1>Please select the vendor from the drop box below for editing</h1>
              <h1>                <?php
$hostname = "localhost";
$db_user = "root";
$db_password = "";
$database = "t2";  
$db_table = "vendmast";  
$db = mysql_connect($hostname, $db_user, $db_password); 
mysql_select_db($database,$db);
?>
                  <select name="name" id="name">
                    <option  value=" " ></option>
                    <?php

$query = "select vend_des From $db_table order by vend_des"; 
$results = mysql_query($query, $db) or die("Error performing query"); 

while($row = mysql_fetch_array($results))
{ ?>
                    <option value="<?php echo $row['vend_des'];
?>"><?php echo $row['vend_des'];
?></option>
                    <?php
}		
 						mysql_close($db);
					?>
                                      </select>
                                </h1>
            </h1>
          </h1>
      </center></td>
    <td width="190">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td width="352" height="45" class="style34">
      <div align="center"> </div></td>
    <td width="22" class="style34">&nbsp;</td>
    <td height="45" class="style34">&nbsp;</td>
    <td width="19">&nbsp;</td>
    <td width="76"><div align="center">
        <input type="submit" name="Submit" value="Submit">
	<INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);"> 
 
</div></td>
    <td width="78">&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</form>

code for displaying the selected record in a textbox: (Code 2)

<?php 
$des=$_POST["name"];
$hostname = "localhost";
$db_user = "root";
$db_password = "";
$database = "t2";  
$db_table = "vendmast";  
$con = mysql_connect($hostname, $db_user, $db_password); 
echo "the name is".$des;

if (!$con)

  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db($database, $con);
$sql="select * from $db_table where vend_des='$des'";
$res=mysql_query($sql,$con);
$num=mysql_numrows($res);
$i=0;

while ($i < $num) {

echo "<form  method='post' action='done' id='update'>"; 
<input type='text' name='code' value="<?php echo $res['vend_code'] ?>"></td>";
echo "<td><input type='text' name='name' value="<?php echo $res['vend_des'] ?>"></td>"; 
echo "<td><input type='text' name='Add' value="<?php echo $res['vend_add1'] ?>"></td>"; 
echo "<td><input type='text' name='Add1' value="<?php echo $res['vend_add2'] ?>"></td>"; 
echo "<td><input type='text' name='Add2' value="<?php echo $res['vend_add3'] ?>"></td>"; 
echo "<td><input type='text' name='City' value="<?php echo $res['vend_city'] ?>"></td>"; 
echo "<td><input type='text' name='Pin' value="<?php echo $res['vend_pin']?>"></td>"; 
echo "<td><input type='text' name='Phone' value="<?php echo $res['vend_phone'] ?>"></td>"; 
echo "<td><input type='text' name='TIN' value="<?php echo $res['vend_tin'] ?>"></td>";
echo "<td><input type='text' name='CST' value="<?php echo $res['vend_cst'] ?>"></td>";


$i++;
                  }  
                   
?>

specify what error or unexpected things happening?

first off, echo your query to check if it's working.
next, make sure you WRAP your code with the code tags before posting. read forum rules http://www.daniweb.com/forums/misc-explaincode.html

$res is not an array, you need to set it as an array before you can use the [].

http://php.net/manual/en/function.mysql-query.php

check the link to see how mysql_query() works.

$sql="select * from $db_table where vend_des='$des'";
$result=mysql_query($sql,$con);
while($res= mysql_fetch_array($result)){

//echo your stuff
}