Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable being cut off when used in form element

Status
Not open for further replies.

coben

Instructor
Apr 16, 2002
50
0
0
US
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(&quot;/var/db_connect();
$fid = $_GET['id'];
$fac_array = @mysql_query(&quot;SELECT * FROM faculty WHERE ID='$fid'&quot;);
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 (&quot;The value for deg1 is: $deg1<p>&quot;); // This prints out ok.
?>
<form action=&quot;&quot; method=&quot;post&quot; name=&quot;newfacutly&quot;>
<table width=&quot;97%&quot; border=&quot;0&quot; cellspacing=&quot;3&quot; cellpadding=&quot;5&quot;>
<tr>
<th>Degree 1:</td>
<td>
<?php
echo (&quot;<input name=deg1 type=text id=deg1 size=70 value=$deg1>&quot;); // This cuts off the variable as shown below.
?>
</td>

If I display the variable by itself (i.e. echo (&quot;$deg1&quot;); 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?
 
more code . what displays it ?

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Pretty typical problem... proper HTML specifies that elements need to be quoted... you say something like...
Code:
echo &quot;<input type=whatever name=whatever value=$deg1>&quot;;

So at the first space, the HTML parser says, down with that element... you need...
Code:
echo '<input type=&quot;whatever&quot; name=&quot;whatever&quot; value=&quot;'.$deg1.'&quot;>';

Notice the combinations of double and single quotes there.

Good luck.

-Rob
 
Thanks for your input. I was given another method to solve the problem which I'd like to share for everyone's info.

<input name=&quot;deg1&quot; type=&quot;text&quot; value=&quot;<?php echo $deg1; ?>&quot;>

I'm new to php and I'm amazed at the flexability it offers over cgi.

Thanks for the responses.
Chris.
 
That method is well-known. It involves switching PHP from HTML to execution mode and back.

Context-switching is fine for relatively simple scripts. But I've found it can clutter code significantly when scripts get complex. This makes it harder to debug code.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top