Value of variable being cut off in form text field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chriso
Forum Commoner
Posts: 31
Joined: Fri Aug 01, 2003 11:52 am

Value of variable being cut off in form text field

Post by chriso »

A variable I'm pulling out of a MYSQL db is being cut short when I try to display it in a form variable. The column type in the db is varchar. Here is some of the script:

<?php
include("/var/www/html/admin/myfunctions.php");
db_connect();
$fid = $_GET['id'];
$fac_array = @mysql_query("SELECT * FROM faculty WHERE ID='$fid'");
if (!$fac_array) {
die('<h2>Error retrieving faculty from database!</h2><br>' .
'Error: ' . mysql_error());
}
$fac_info = mysql_fetch_array($fac_array);

$lname = $fac_info['LNAME'];
$fname = $fac_info['FLNAME'];
$deg1 = htmlspecialchars($fac_info['DEG1']);
$deg2 = htmlspecialchars($fac_info['DEG2']);
$deg3 = htmlspecialchars($fac_info['DEG3']);
echo ("The value for deg1 is: $deg1<p>"); // This prints out ok.
?>
<form action="" method="post" name="newfacutly">
<table width="97%" border="0" cellspacing="3" cellpadding="5">
<tr>
<th>Degree 1:</td>
<td>
<?php
echo ("<input name=deg1 type=text id=deg1 size=70 value=$deg1>"); // This cuts off the variable as shown below.
?>
</td>

If I display the variable by itself (i.e. echo ("$deg1"); it display just fine. However, as soon as I add it to a form element, it gets cut off. For example:

B.S. Univeristy of Idaho would appear as B.S.
B. S., Business Administration would appear as B.

I'm using the form so people can update information. Any ideas?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

&lt;html&gt;
	&lt;body&gt;
		&lt;!-- compare --&gt;
		&lt;input type=text value=just a test /&gt;
		&lt;br /&gt;
		&lt;!-- to --&gt;
		&lt;input type="text" value="just a test" /&gt;
	&lt;/body&gt;
&lt;/html&gt;
then replace
<?php
echo ("<input name=deg1 type=text id=deg1 size=70 value=$deg1>"); // This cuts off the variable as shown below.
?>
by

Code: Select all

<input name="deg1" type="text" id="deg1" size="70" value="<?php echo $deg1; ?>">
in case of doubt always quote the properties of an html-element
chriso
Forum Commoner
Posts: 31
Joined: Fri Aug 01, 2003 11:52 am

Post by chriso »

Many thanks!!
Post Reply