0

I have an issue which I can't seem to fix.

I have a form and inside the form is a <textarea> which has text already populated. My problem is when I go to look at the form, the text displays outside of the textarea, not inside which is problematic!

I have the following:

HTML

<div class="passenger_Container">
    <div class="names">
        <strong>Joe Bloggs</strong>
    </div>

    <div class="package">
        <!-- passenger detail goes here. You will find the code in  includes/passenger_Detail.php -->
    </div>
</div> <!-- .passenger_Container -->

jQuery

j$('.names strong').click(function(e) {
        //find passenger ID - note input[name='customer_ID'] isn't shown in this example
        var customer_ID = j$(this).closest('.passenger_Container').find("input[name='customer_ID']").val();
        //Use jQuery to find placement of returned data
        var insert_Data = j$(this).closest('.passenger_Container').find('.package');


        j$.ajax({        
           type: "POST",
           url: "/include/passenger_Detail.php",
           data: { customer_ID_Data : customer_ID },
           success: function(data) {
                //console.log("Returned data: "+data);  
                //get returned data and add into appropriate place
                insert_Data.html(data);

                //re-initialise WYSIWYG editor. Notes is the ID to re-initialize 
                tinyMCE.execCommand('mceAddControl', true, 'notes');
           }
        }); 
    });

PHP - passenger_Detail.php

<?php
$customer_ID = $_REQUEST['customer_ID_Data'];
$query = mysqli_query($conn,"SELECT * FROM Customers WHERE customer_ID = ".$customer_ID." ORDER BY l_Name asc")
    or die("Error: ".mysqli_error($conn));
$row = mysqli_fetch_array($query);
$orderQuery = mysqli_query($conn,"SELECT * FROM Orders WHERE customer_ID=".$row['customer_ID']."")
    or die("Error: ".mysqli_error($conn));
$rowOrder = mysqli_fetch_array($orderQuery);
?>
<textarea type="text" name="notes" class="form-control notes" id="notes" />
<?php 
    echo $rowOrder['Notes']; 
?>
</textarea>

TL;DR - text echoed ($rowOrder['Notes'];) in PHP file displays outside of textarea, not inside.

I don't know what's causing this. Any help would be fantastic!

Akira Dawson
  • 1,247
  • 4
  • 21
  • 45
  • 1
    Stop looking at the PHP. Figure out what is wrong with the HTML you are generating (so look at the generated HTML by viewing the source (not inspecting the DOM!) in a browser). Use a [validator](http://validator.w3.org). Then go back and stop the PHP from outputting whatever it is that is making it wrong. – Quentin Sep 17 '14 at 08:32
  • 2
    **Danger**: You are **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that you need to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Sep 17 '14 at 08:33
  • 2
    Remove the / from `id="notes" />` – mplungjan Sep 17 '14 at 08:33
  • @Quentin Thank you for pointing that out. That is on my "to do" list for sure :) – Akira Dawson Sep 17 '14 at 08:38
  • Thank you everyone else for the input.. Can't believe it was such a minuscule error. – Akira Dawson Sep 17 '14 at 08:38

1 Answers1

4

Remove the trailing slash from the textarea opening tag:

Instead of:

<textarea type="text" name="notes" class="form-control notes" id="notes" />

it should be:

<textarea type="text" name="notes" class="form-control notes" id="notes">
Vivek Jain
  • 3,811
  • 6
  • 30
  • 47
  • You beauty. Can't believe it was such a small error. After looking at the same page for more than 3 hours, it really gets to you! Thanks mate, greatly appreciated – Akira Dawson Sep 17 '14 at 08:39
  • 1
    Not worth an answer. Already answered in comments and now cannot be deleted by Akira. – mplungjan Sep 17 '14 at 08:45