Good morning, I'll keep this simple, I have a form that I need to populate with the contects of a MySQL database. I've tested that the 'gathering information' script works properly via a SELECT command. However, when I try to set the value of a text form field using the results, I keep getting this instead of the value itself...

<?php echo $row; ?>

here is the assosciated code. It is contained within an HTML file after the body tag

<?php
$DBhost = "localhost";
$DBuser = "xxxx";
$DBpass = "xxxx";
$DBName = "xxxx";
$table = "xxxx";

# Defining variables with form POST data
$selectPart = htmlspecialchars($_POST['selectPart']);

mysql_connect("$DBhost","$DBuser","$DBpass") or die(mysql_error());

mysql_select_db("$DBName") or die(mysql_error());

$query = "SELECT * FROM xxxx WHERE partID=$selectPart";

$result = mysql_query($query);

if (!$result) {
				$message = 'invalid Query: ' . mysqyl_error() . "\n";
				$message .= 'Whole Query: ' . $query;
				die($message);
			  }

$row = mysql_fetch_assoc($result);

?>

This part works as I've tested it with an echo $row; and so on for the other fields in the array.

When I try to populate the form fields however,

<td width='200'><input type='text' name='fname' id='fname' value="<?php echo $row['$fname']; ?>"></td>

I get the line I mentioned above (<?php echo $row; ?>)in the field instead of the value.

Any help is appreciated!

- Lou

OOPS...the line

<td width='200'><input type='text' name='fname' id='fname' value="<?php echo $row['$fname']; ?>"></td>

should have been

<td width='200'><input type='text' name='fname' id='fname' value="<?php echo $row['fname']; ?>"></td>

Are you serving the page as php? For example, does it have the php extension.

commented: You are too clever by far KK +7

(insert choice words here)

In my grandeur I figured for testing purposes I'd just embed it in my html file not thinking it wasn't being served as php...

Thanks, my brain thanks you too :)

Amazing how it works the way it should when used the way it was meant to be :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.