Displaying the data from DB in the textfiles

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ssharifi
    New Member
    • Apr 2010
    • 11

    Displaying the data from DB in the textfiles

    Hi,
    I have an editing form for my users in which they can change their profiles and the change is saved in database and also displayed for the user.the problem is that testfield that have varchar type only display the first word of what user typed.for example if a user wants to change his last name from 'salehi' to 'salehie rashid' the complete new lastname will be updated in database but in the textfield only the first word(before space) is displayed that is 'salehie'. the textarea,howeve r display the address correctly and only the textfields are like this to show only one word
    why is it like this?and what can I do to solve the problem
    the code related is:
    Code:
    <?php
     if(isset($_POST['username'])){
    mysql_query("UPDATE user SET username = '{$_POST['username']}', name = '{$_POST['name']}',  lastname = '{$_POST['lastname']}',address = '{$_POST['address']}' WHERE id = {$_SESSION['id']}") or die(mysql_error());
    $res = mysql_query("SELECT * FROM user WHERE id = " . $_SESSION['id']); 
    $row = mysql_fetch_assoc($res);
    ?>
    <form action="edit_account.php" method="post" enctype="multipart/form-data">
    
    <table>
    <tr><td>Username:</td>
    <td><input type="text" name="username" value=<?= $row["username"] ?> ></td></tr>
    <tr><td>Name:</td>
    <td><input type="text" name="name" value=<?= $row["name"] ?>> </td></tr>
    <tr><td>Last Name:</td>
    <td><input type="text" name="lastname" value=<?= $row["lastname"] ?> ></td></tr>
    <tr valign="top"><td>Address:</td>
    <td><textarea name="address" cols="23" rows="4"><?= $row["address"]?> </textarea> </tr>
    <tr><td><label>image:</label></td>
    <td><input name="file" type="file"/></td></tr>
    <tr><td><input type="submit" id="add" value="save" name="submit"></td>
    </table>
    </form>
    and the table (in HeidiSQL) is like this:
    Code:
    Create table if not exists user
    (id INT UNSIGNED NOT NULL auto_increment,
    username VARCHAR(15),
    password VARCHAR(40),
    name VARCHAR(15) NOT NULL,
    lastname VARCHAR(40) NOT NULL,
    address VARCHAR(100) NOT NULL,
    PRIMARY KEY(id))
    Last edited by Atli; Apr 8 '10, 07:21 PM. Reason: Added [code] tags.
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    I think your HTML / PHP mixture is wrong
    Code:
    <td><input type="text" name="lastname" 
    value=<?= $row["lastname"] ?> ></td></
    The double quotes are wrapping the array key instead of value
    Code:
    <td><input type="text" name="lastname"
    value="<?= $row['lastname'] ?> "></td></
    Also shorttags <? are out in later versions. Use <?php

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hey.

      code green got it right.

      In HTML, attributes should be quoted. If they are not, only the value up until the first alpha-numeric character (like a space) is considered a part of the value. The rest is parsed as a separate attribute, which may cause errors.

      For example, consider this tag:
      [code=html]<input type=text value=my name>[/code]
      The HTML parser would parse this tag into something like:
      [code=text]Input = array(
      'attributes' => array(
      'type' => 'text',
      'value' => 'my',
      'name' => null
      )
      )[/code]
      Because of the space between "my" and "name", the HTML parser assumes "name" is another attribute; one without any value. And because there is no such attribute, it is either discarded as junk or added to the DOM as a non-standard attribute.

      The proper way to create this tag would be to do:
      [code=html]<input type="text" value="my name">[/code]
      Which a HTML parser would read as:
      [code=text]Input = array(
      'attributes' => array(
      'type' => 'text',
      'value' => 'my name',
      )
      )[/code]

      Comment

      • ssharifi
        New Member
        • Apr 2010
        • 11

        #4
        hi,thanks for the help.
        my problem is solved now

        Comment

        Working...