PDA

View Full Version : help with text box data



solarcom
08-22-2006, 05:58 PM
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?

codeexploiter
08-23-2006, 10:22 AM
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

costas
08-23-2006, 10:29 AM
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!

costas
08-23-2006, 10:31 AM
Or it's even better to use:

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

DimX
08-23-2006, 10:36 AM
solarcom, do you get any error or something?

codeexploiter
08-23-2006, 10:37 AM
Hi



$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


$part = $row["part"]; //you introduced this one less complicated approach

<input type="text" name="part" size="40" value="<?=$part;?>">

Thats it

Code Exploiter

solarcom
08-23-2006, 05:11 PM
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.

solarcom
08-23-2006, 05:15 PM
By the way, the site is on a shared server and I don't have access to the installation files, etc.

mwinter
08-23-2006, 10:27 PM
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
$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

solarcom
08-24-2006, 04:49 PM
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.