Need the eye of a Guru (UPDATE Query)

I have a textarea which when edited is then fired off to MySQL to update the row, everything looks ok to me (but im a bit of a newbie) but the row is not updating.

Firtly the content is selected from a dropdown selection and when the page is submitted it populates the textarea and fields with the correct row for editing, i have attached the code, its probably something to do with how im calling the id in the UPDATE querys WHERE function, but im at a lost now for the last few days… thanks

<?php 
include("header.php");

if($session->logged_in){
// If submitted, check the value of "select". If its not blank value, get the value and put it into $select.
if(isset($select)&&$select!=""){
$select=$_GET['select'];
}
?>
<form id="form1" align="center" name="form1" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="select">
<option value="">Select Template For Editing</option>
<?php
// Get records from database (table "listings").
$q=mysql_query("SELECT * FROM listings ORDER BY id");

// Show records by while loop.
while($row_list=mysql_fetch_assoc($q)){
?>
<p align="center">
<option value="<?php echo $row_list['id']; ?>"><?php echo $row_list['company_name']; ?></option>
<?php
// End while loop.
}
?>
</select>
<input type="submit" name="Submit" value="Select" />
</form>

<?php
// If you have selected from list box.
if(isset($select)&&$select!=""){

// Get records from database (table "name_list").
$result=mysql_query("SELECT * FROM listings WHERE id='$select'");
$row=mysql_fetch_assoc($result);
?>
<div id="tempdetails">The listing that you have chosen to edit from is:&nbsp;&nbsp;<font color="red"><u><?php echo $row['company_name']; ?></u></font></div><!-- /tempdetails --> 
<p>
<!-- ##### THIS FORM SHOWS (or should show) THE INFORMATION FROM EDITOR1 FIELD IN db ##### -->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="test" method="post">
<p align="center"><font color="red">All fields are required.</font></p>
            <p align="center">Location:&nbsp;<input type="text" name="location" size="40" value="<?php echo $row['location']; ?>" />&nbsp;&nbsp;
             Company Name:&nbsp;<input type="text" name="company_name" size="40" value="<?php echo $row['company_name']; ?>" /></p>
            <textarea id="editor1" name="editor1"><?php echo $row['editor1']; ?></textarea>
            <script type="text/javascript">
                CKEDITOR.replace( 'editor1',
 {
     enterMode : Number(2),
        filebrowserBrowseUrl : 'ckfinder/ckfinder.html',
 	filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?type=Images',
 	filebrowserImageUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
 	
     
 }
   );
            </script>
           </p>
           <p>
            <input type="submit" name="submit" />
           </p>
</form>
<?php
// End if statement.
}
?>

<?php 
 // this part updates the database with the newly created business listing
    
    if (isset($_POST['submit']))
    {
     
     $id= $_POST['id'];

     //$id = $row_list['id'];
     $location = $_POST['location'];   
     $company_name = $_POST['company_name'];
     $editor1 = str_replace("\
\\r","<br />",$_POST['editor1']);
     
     // lets populate the database with this new information
     $q = ("UPDATE listings SET location='$location', company_name='$company_name', editor1='$editor1' WHERE id='$id'");
     

//echo "$q<br>";

     $result = mysql_query($q) or die("<b>A fatal MySQL error occured</b>.\
<br />Query: " . $q . "<br />\
Error: (" . mysql_errno() . ") " . mysql_error());
     
     // success or failure ?
     if ($result) echo "<p align=\\"center\\"><u>The newly edited listing was successfully inserted into the Listing's database</u></p>";
     else echo "<p align=\\"center\\"><font color=\\"red\\">There was a problem, the data got lost on the way.</font></p>";
    }
    
 }else {
        /* Link back to main */
header("Location: index.php");
    }
?>

     <!-- ##### END OF EDITING AND SENDING THE EDITED HTML TO THE "LISTINGS" db TABLE ##### --> 
</div><!-- /editor -->
</div><!-- /editor_wrapper -->
<!-- START OF FOOTER -->
                                  
     </div><!-- /wrapper -->
</body>
</html>

Sixth: Found the problem. Your script is looking for id as $id = $_POST[‘id’] … you dont have a form field passing id along.

second get rid of the dangling paragraph tag inside your while loop - it’s pointless.

third sanitize your input!

fourth unless ID is a string, you dont need quotes around it in the query.

fifth: When in doubt, echo the query out. Check and see that the query is valid by manually running it through the mysql engine. The result can return TRUE, even if it edited 0 rows (Success to the engine does not necessarily mean it did what you WANTED it to, simply that whatever you told it to do didnt throw any big errors)

To start, change


if(isset($select)&&$select!=""){
  $select=$_GET['select'];
}

in


if (isset($_GET['select']) && $_GET['select'] != "") {
  $select = $_GET['select'];
}