www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] Extra white-space in textarea

  1. #1
    Join Date
    Sep 2008
    Posts
    52

    resolved [RESOLVED] Extra white-space in textarea

    I keep getting this extra white-space when I load content from a mysql database into a textarea of a form. I've tried converting it into a string a then use the trim() function but I keep getting the same problem. Any ideas?

    PHP Code:
    <?php
    include "admin/conn/config.php";
    include 
    "admin/conn/connect_database.php";
    $page_update "";
    if (isset(
    $_POST['update'])){
        
    $update $_POST['update'];
        
    $sql="UPDATE updates SET message='$_POST[update]', date=CURDATE()";
        if (!
    mysql_query($sql,$opendb)){
            die(
    'Error: ' mysql_error());
         }
        else {
            
    $page_update "<h2>Sidan har blivit uppdaterad!</h2>";
        }
    }
    ?>
    <!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>Untitled Document</title>
    </head>

    <body>
        <?php
        $result 
    mysql_query("SELECT * FROM updates ORDER BY date DESC LIMIT 1");
        
    $row mysql_fetch_array($result);
        echo 
    $row['message']." (".$row['date'].")";
        echo 
    $page_update;
        
    ?>
        <form action="" id="" method="post">
            <textarea cols="60" rows="10" name="update">
            <?php
            $result 
    mysql_query("SELECT * FROM updates");
            
    $row mysql_fetch_array($result);
            
    $str $row['message'];
            echo 
    trim($str);
            
    ?>
            </textarea>
            <br />
            <input type="submit" value="Spara" class="krs-edit_align-r"/>
      </form>
    </body>
    </html>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,633
    Remove the newlines/spaces between the <textarea> tags and the <?php tags:
    PHP Code:
            <textarea cols="60" rows="10" name="update"><?php
            $result 
    mysql_query("SELECT * FROM updates");
            
    $row mysql_fetch_array($result);
            
    $str $row['message'];
            echo 
    trim($str);
            
    ?></textarea>
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Sep 2008
    Posts
    52
    Thanks! It worked perfectly!!

  4. #4
    Join Date
    Sep 2008
    Posts
    52
    Is there a better way of putting out the $page_update = "<h2>Sidan har blivit uppdaterad!</h2>"?

    Now I have an empty variable that first outputs nothing until the form has been submitted. With javascript or something?

  5. #5
    Join Date
    May 2012
    Posts
    1

    Thumbs up Removed whitespace

    Quote Originally Posted by NogDog View Post
    Remove the newlines/spaces between the <textarea> tags and the <?php tags:
    PHP Code:
            <textarea cols="60" rows="10" name="update"><?php
            $result 
    mysql_query("SELECT * FROM updates");
            
    $row mysql_fetch_array($result);
            
    $str $row['message'];
            echo 
    trim($str);
            
    ?></textarea>
    Brilliant! Thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles