tatt727 0 Newbie Poster

Hi, I have written a code that retrieves values from a MySql database and displays it in a table. So far so good. Then, what I want to do is have the user click on edit and the row that contains the record to be edited becomes editable boxes. I've even managed to do that but for some reason after the edit link is pressed the only first row is in a table, the rest are just listed, including the editable row, underneath.

Where am I going wrong? How do I get it so all of the records are listed in the table?

Ignore the rest of the code, this is a work in progress, it's just the table at the bottom I'm struggling with at the moment

<?PHP
session_start();
?>
<?php
//Connect to server
$conn = mysql_connect ("localhost", "tatty27", "monkeyboy") or die ("Could not connect to database.");
//connect to database
mysql_select_db("tatty27_customers") or die ("Database does not exist.");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit php</title>
</head>

<body>
<h2>Edit</h2>
 <?php
       $id=$_GET['id'];
 	   echo $id.'<br />';
	   echo 'tracey'.'<br />';
 
 /*$sql="SELECT * FROM customers WHERE customerID ='$id'";*/
 
 $sql="SELECT * FROM customers where customerID = $id";
 
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);

 
echo $rows['name'];
$url = $_SERVER['PHP_SELF'];

echo '<table border="1">';
	echo '<tr>';
	 echo '<td nowrap>';
	 echo "<a href=\"".$url."?sortBy=customerID\">Sort By Customer ID</a>";
	 echo "<a href=\"".$url."?sortBy=customerID&desc=1\">[DESC]</a>";
	 echo '</td>';
	 
	 echo '<td nowrap>';
	 echo "<a href=\"".$url."?sortBy=name\">Sort By Name</a>";
	 echo "<a href=\"".$url."?sortBy=name&desc=1\">[DESC]</a>";
	 echo '</td>';
	 
	 echo '<td nowrap>';
	 echo "<a href=\"".$url."?sortBy=address\">Sort By Address</a>";
	 echo "<a href=\"".$url."?sortBy=address&desc=1\">[DESC]</a>";
	 echo '</td>';
	 
	 echo '<td nowrap>';
	 echo "<a href=\"".$url."?sortBy=postcode\">Sort By Postcde</a>";
	 echo "<a href=\"".$url."?sortBy=postcode&desc=1\">[DESC]</a>";
	 echo '</td>';
	 
	 echo '<td nowrap>';
	 echo "<a href=\"".$url."?sortBy=telephone\">Sort By Telephone</a>";
	 echo "<a href=\"".$url."?sortBy=telephone&desc=1\">[DESC]</a>";
	 echo '</td>';
	 
	 echo '<td nowrap>';
	 echo "<a href=\"".$url."?sortBy=email\">Sort By Email</a>";
	 echo "<a href=\"".$url."?sortBy=email&desc=1\">[DESC]</a>";
	 echo '</td>';



   $sql="SELECT * FROM customers";	 
	 
	if(isset($_REQUEST['sortBy']))
	{
		$sql="SELECT * FROM customers order by ".$_REQUEST['sortBy'];
		if(isset($_REQUEST['desc']))
		{
			$sql.=" DESC";
		}
			
	}


   $result = mysql_query($sql);
   //repeat loop for each row of results returned
while ($row = mysql_fetch_array($result)or die(mysql_error())){
if($row[customerID] != $id){
							echo "<tr><td>$row[customerID]</td><td>$row[name]</td><td>$row[address]</td><td>$row[postcode]</td><td>$row[telephone]</td><td>$row[email]</td><td><a href='edit.php?id=$row[customerID]'>[Edit]</a><a href=\"".$url."?sortBy=email&desc=1\">[Delete]</a></td>";
			
			}else{

	echo "<form name=\"form1\" method=\"post\" action=\"\">
				<td nowrap><input name=\"custID\" type=\"text\" id=\"custID\" value=\"$row[customerID]\"></td>
			     <td><input name=\"name\" type=\"text\" id=\"name\" value=\"$row[name];\"></td>
				<td><input name=\"address\" type=\"text\" id=\"address\" value=\"$row[address]\"></td>
				<td><input name=\"postcode\" type=\"text\" id=\"postcode\" value=\"$row[postcode]\"></td>
				<td><input name=\"telephone\" type=\"text\" id=\"telephone\" value=\"$row[telephone]\"></td>
				<td><input name=\"email\" type=\"text\" id=\"email\" value=\"$row[email];\"></td>
				<td><a href='edit.php?id=$row[customerID]'>[Edit]</a><a href=\"".$url."?sortBy=email&desc=1\">[Delete]</a></td></form>";																																						
			}
	echo '</tr>';
echo'<table>';
   
}

   ?>
</body>
</html>