Results 1 to 10 of 10

Thread: help with text box data

  1. #1
    Join Date
    Aug 2006
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation help with text box data

    http://

    I have a catalogue with a MySQL database using PHP. There is a form for editing products and I want to show the data already in the database in the text boxes when the form loads. I tried using value= like this :

    <input type="text" name="part" size="40" value="<?php echo($row["part"]); ?>">

    But it doesn't work. I searched the internet and there are dozens of examples showing exactly the same thing. What am I doing wrong?

  2. #2
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Thumbs up

    Hi

    Try this method
    <input type="text" name="part" size="40" value="<?=$row["part"];?>">

    Rather than the method you mentioned in your posting. This is the popular PHP/ASP method for putting values into some containers (form fields).

    Hope this will help you.

    Regards

    Code Exploiter

  3. #3
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I think it's better to try this:

    <input type="text" name="part" size="40" value="<? echo $row["part"];?>">

    I had a similar problem and it was solved like that.
    Hope I helped!

  4. #4
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Or it's even better to use:

    $part = $row["part"];
    <input type="text" name="part" size="40" value="<? echo $part;?>">

  5. #5
    Join Date
    Jun 2006
    Posts
    182
    Thanks
    0
    Thanked 14 Times in 14 Posts

    Default

    solarcom, do you get any error or something?

  6. #6
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Thumbs up

    Hi

    Code:
    $part = $row["part"]; <input type="text" name="part" size="40" value="<? echo $part;?>">
    Actually most of the users prefer the other method since it avoids the echo function call beginners will find it difficult to understand.

    Since we have another simple method then we can go with that na

    PHP Code:
    $part $row["part"]; //you introduced this one less complicated approach 
    <input type="text" name="part" size="40" value="<?=$part;?>">

    Thats it

    Code Exploiter

  7. #7
    Join Date
    Aug 2006
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks for trying everyone. I've tried every way and still nothing in the text box. There are no error messages, the page will load fine, I right click to check the source, the "value=" has the data from the database(value="protege control arms" for example) but it just doesn't display in the text box. I do't get it, I check the source for other websites and it looks exactly the same with the value= being shown, of course I can't see their PHP code.

  8. #8
    Join Date
    Aug 2006
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    By the way, the site is on a shared server and I don't have access to the installation files, etc.

  9. #9
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by solarcom
    Thanks for trying everyone. I've tried every way and still nothing in the text box. There are no error messages, the page will load fine, I right click to check the source, the "value=" has the data from the database(value="protege control arms" for example) but it just doesn't display in the text box.
    Can you post a link to a minimised working example and its accompanying source code? A minimised example is one that uses the simplest code that still demonstrates the problem. For example, if you get your data from a database, replace the query result with an array containing sample (though realistic) data.

    Just to ensure that there's nothing critically wrong with your server, perhaps you should try something really trivial like:

    PHP Code:
    <?php
    $row 
    = array('part' => 'Some text');
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

    <html>
        <head>
            <title>PHP test</title>
        </head>

        <body>
            <div><input value="<?php echo $row['part'];?>"></div>
        </body>
    </html>

    Regarding the syntax debate, I wouldn't say that any example is perfect, though perhaps the original is best. I would use what I posted above.

    Delimiters other than <?php depend on specific configuration options (short_open_tag and asp_tags) that, in the recommended settings, are disabled. The long form is always recognised and code that is intended to be used by other people should not use a shortened form.

    The echo "function" is not a function at all; it is a language construct. It doesn't behave like a function, but to use parentheses invites the misconception that it does. Moreover, to use multiple operands, one cannot use parentheses.

    As far as an expression versus assignment to a variable is concerned, I would choose the former in simple cases like the above. I would use the latter with longer expressions, or if the result of that expression will be used elsewhere.

    Finally, the terminating semicolon is optional as the statement is immediately followed by a closing tag (?>). Whether to retain the semicolon or not is simply a style choice, and I choose to keep it.

    Mike

  10. #10
    Join Date
    Aug 2006
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    A thousand thank you's, it finally works. Very confusing, but the only thng I changed was <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> to <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> and used the <div></div> tags.

Bookmarks

Posting Permissions

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