Problem echo'ing retrieved data

I am having a problem showing retrieved MySQL data on page in a textarea, My db is small just 3 fields which are

rowID(INT)
name(VAR)
editor1(TEXT)

firstly the user chooses from a dropdown selector (first commented block of code)… this is then submitted and should populate a textarea on the page, however it doesnt,no errors are show (error reporting is on and i have also ran ("Query failed: " . mysql_error() . " Actual query: " . $query) and still no error shows im no php guru (new starter if the truth be told) but i think there must be an error in assigning the variable to “editor1” in the block of code below the dropown.

Anybody have any insights please? im not asking for free code just pointers and advice to where i have gone wrong, thanks for your time…


<!-- ##### CREATE THE DROPDOWN SELECTION ##### -->

<form action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
function create_dropdown($identifier,$pairs,$firstentry)
{
  $dropdown ="<select name=\\"$identifier\\">";
  $dropdown .= "<option name=\\"Fetch Template\\">$firstentry</option>";
  
  foreach($pairs AS $value => $name)
  {
   $dropdown .="<option name=\\"$value\\">$name</option>";
  }
  echo "</select>";
  return $dropdown;
}

// Lets gather the data from the table
$q = ("SELECT rowID, name FROM templates ORDER BY name");
$result = mysql_query($q);

// Now its time to build an array based on the templates table data
while($row = mysql_fetch_array($result))
{
    $value = $row["rowID"];
    $name = $row["name"];
    $pairs["$value"] = $name;
}

echo create_dropdown("rowID",$pairs,"Choose A Template");
?>
<input type="submit" name="submit" value="Fetch Template" />
</form>
</p>
</div>
<!-- ##### END THE DROPDOWN ##### -->

<!-- ##### BEGIN GETTING THE INFORMATION FROM THE SUBMITTED DROPDOWN DATA ##### -->
<?php

// If the form has been submitted then:
if (isset($_POST['rowID']))
{
    // Get the posted rowID
    $rowID = $_POST['rowID'];
    
    // Select the data that corresponds to the selected rowID
    $q = ("SELECT editor1 FROM templates WHERE rowID='$rowID");
    
    $result = mysql_query($q);
    
    // Assign this information to a variable
    list($editor1) = mysql_fetch_row($result);

}
?>

     <!-- ##### THIS FORM SHOWS (or should show) THE INFORMATION FROM EDITOR1 FIELD IN db ##### -->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <p>Location:&nbsp;<input type="text" name="location" size="40">&nbsp;&nbsp;
             Company Name:&nbsp;<input type="text" name="company_name" size="40"></p>
            <input type="hidden" name="rowID" value="<?php echo (isset($rowID))?$rowID:""; ?>">
            <textarea name="editor1"><?php echo (isset($editor1))?$editor1:""; ?></textarea>
            <script type="text/javascript">
                CKEDITOR.replace( 'editor1',
 {
     filebrowserBrowseUrl : 'ckfinder/ckfinder.html',
     filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?type=Images',
     filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?type=Flash',
     filebrowserUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
     filebrowserImageUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
     filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
 } 
 );
            </script>
           </p>
           <p>
            <input type="submit" name="submit" />
           </p>
</form>
     <!-- ##### END OF RETRIEVED FIELD DATA ##### -->
     
     <!-- ##### UPDATED CONTENT IS THEN INSERTED ON SUBMIT TO "LISTINGS" TABLE IN db ##### --> 
<?php 
 // this part updates the database with the newly created business listing
    
    if (isset($_POST['submit']))
    {
     $rowID = $_POST['rowID'];
     $location = $_POST['location'];
     $company_name = $_POST['company_name'];
     $editor1 = $_POST['editor1'];
     
     // lets populate the database with this new information
     
     $q = ("INSERT INTO listings SET location='$location', company_name='$company_name', editor1='$editor1'");
     
     $result = mysql_query($q);
     
     // success or failure ?
     if ($result) echo "<p>The new listing was successfully inserted into the database</p>";
     else echo "<p>There was a problem, the data got lost on the way.</p>";
    }
?>

     <!-- ##### END OF EDITING AND SENDING THE EDITED FORM TO THE "LISTINGS" db TABLE ##### -->

I guess you need to use $_GET array instead of $_POST (not for the whole script but for the display part)

also, note that $rowID must be sanitized before being put into query,
$rowID = mysql_real_escape_string($rowID);

Thanks for that, i changed the lines


// If the form has been submitted then:

if (isset($_POST['rowID']))

{

    // Get the posted rowID

    $rowID = $_POST['rowID'];

to $_GET but the came across an error of

mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\\wamp\\www\\simplycms\\create_new_listing1.php on line 59

which refers to this line

// Assign the template information to a variable
    list($editor1) = mysql_fetch_row($result);

referring to my book (Gilmore, PHP5 and mysql novice - pro) its saying that boolean is supporting of only 2 values, (which i would take as being for example being used for male or female checkbox or similar,) how does this apply to the code?..

regards to sanitizing thanks for the heads up, i aready have a function to assign but while im trying to get this to work i want to keep my code light for the meanwhile (less to see, less to wade my way through) and add the function once thinks are hunky dory…

edit

i read the boolean error thing the wrong way around, its actually a resource thats needed, again a quick loo at the book says it could be a connectivity issue, if thats the case then how come the dropdown part of the script works and the updating part, but not the middle?..

yes, you have an error in the query.
try to find it yourself.
print your query out and watch what’s wrong.

30 hours later and more coffee than Kenco and im still stuck, i managed to get the page code error free (apart from the fact i cannot declare the echo)

<!-- ##### CREATE THE DROPDOWN SELECTION ##### -->

<form action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
function create_dropdown($identifier,$pairs,$firstentry)
{
  $dropdown ="<select name=\\"$identifier\\">";
  $dropdown .= "<option name=\\"Fetch Template\\">$firstentry</option>";
  
  foreach($pairs AS $value => $name)
  {
   $dropdown .="<option name=\\"$value\\">$name</option>";
  }
  echo "</select>";
  return $dropdown;
}

// Lets gather the data from the templates table
$q = ("SELECT rowID, name FROM templates ORDER BY name");
$result = mysql_query($q);

// Now its time to build an array based on the templates table data
while($row = mysql_fetch_array($result))
{
    $value = $row["rowID"];
    $name = $row["name"];
    $pairs["$value"] = $name;
}

echo create_dropdown("rowID",$pairs,"Choose A Template");
?>
<input type="submit" name="submit" value="Fetch Template" />
</form>
</p>
</div>
<!-- ##### END THE DROPDOWN ##### -->

<!-- ##### BEGIN GETTING THE INFORMATION FROM THE SUBMITTED DROPDOWN DATA ##### -->

<?php

//$conn = mysql_connect("localhost", "root", "") or die ("can not connect");
//mysql_select_db("simplycms") or die ("cant find database");

// If the form has been submitted then:
if (isset($_GET['rowID']))
{
    // Get the posted rowID
    $rowID = $_GET['rowID'];
    
    // Select the data that corresponds to the selected rowID
    $q = ("SELECT editor1 FROM templates WHERE rowID='$rowID'") or die("A MySQL error has occurred.<br />Your Query: " . $your_query . "<br /> Error: (" . mysql_errno() . ") " . mysql_error());
    
    $result = mysql_query($q)or die("A MySQL error has occurred.<br />Your Query: " . $your_query . "<br /> Error: (" . mysql_errno() . ") " . mysql_error());
    
    // Assign the template information to a variable
    list($editor1) = mysql_fetch_row($result);

}
?>

<!-- ##### 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>Location:&nbsp;<input type="text" name="location" size="40" />&nbsp;&nbsp;
             Company Name:&nbsp;<input type="text" name="company_name" size="40" /></p>
            <input type="text" name="rowID" value="<?php echo (isset($rowID))?$rowID:""; ?>">
            <textarea name="editor1"><?php echo (isset($editor1))?$editor1:""; ?></textarea>
            <script type="text/javascript">
                CKEDITOR.replace( 'editor1',
 {
     filebrowserBrowseUrl : 'ckfinder/ckfinder.html',
     filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?type=Images',
     filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?type=Flash',
     filebrowserUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
     filebrowserImageUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
     filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
 } 
 );
            </script>
           </p>
           <p>
            <input type="submit" name="submit" />
           </p>
</form>
     <!-- ##### END OF RETRIEVED FIELD DATA ##### -->

the boolean error was because i had a single quote missing, now the script is reporting no errors but stll nt populating the textarea, any ideas as to what i need to change?.. thanks…