Page 1 of 1

Variable in text box displays differently with print

Posted: Sun Nov 30, 2003 6:20 am
by jim_73_mk1
I'm trying to fill a text field with a value passed from a form on a previous page. The problem is the text passed ($Title) is all there but in the text box it only shows the first word. I found another way to display all the text but it will be tedious to code. Maybe someone can explain why the two processes work differently?

Code: Select all

<?php
$Title = "This is New Stuff"; 
print ("
	<form action='NewBook.php' method='post' name='EditBook'>
	<table width=80% cellspacing=5>
		<tr>
			<td></td>
			<td><strong>Your Book Information</strong></td>
			<td><strong>Matching Book Information</strong></td>
		</tr>
		<tr>
			<td>Title</td>
			<td><input name='Title' type='text' value=" . $Title . "></td>
			<td></td>
		</tr>
		<tr>
			<td>Title</td>
");
?>
			<td><input name='Title' type='text' value=" <?php print $Title; ?> "></td> 
<?php
print ("
			<td></td>
		</tr>
       </table>
		</form>
");
?>

Posted: Sun Nov 30, 2003 6:29 am
by vigge89
WHy don't you just do like this?;

Code: Select all

<?php

$Title = "This is New Stuff";

echo <<<EOD
<form action="NewBook.php" method="post" name="EditBook">
<table width="80%" cellspacing="5">
   <tr>
      <td></td>
      <td><strong>Your Book Information</strong></td>
      <td><strong>Matching Book Information</strong></td>
   </tr>
   <tr>
      <td>Title</td>
      <td><input name="Title" type="text" value="$Title"></td>
      <td></td>
   </tr>
</table>
</form>
EOD;

?>

Posted: Sun Nov 30, 2003 11:50 am
by mchaggis
Just a note... single quotes within html tags isn't allowed, you have to use double quotes, so vigge89's answer is probable the best way to do it or:

Code: Select all

<?php
$Title = "This is New Stuff";
?>
<form action="NewBook.php" method="post" name="EditBook">
<table width="80%" cellspacing="5">
   <tr>
      <td></td>
      <td><strong>Your Book Information</strong></td>
      <td><strong>Matching Book Information</strong></td>
   </tr>
   <tr>
      <td>Title</td>
      <td><input name="Title" type="text" value="<?=$Title?>"></td>
      <td></td>
   </tr>
</table>
</form>

?>
One thing to look out for tho is if $Title contains a double quote it will break you out of the input box....