0

I am trying to embed a raw PHP variable $nombre into the HTML, here is the PHP:

Edit <?php echo $nombre; ?> .
<form action="getfile.php" method="post" name="uploadForm" id="uploadForm"
enctype="multipart/form-data"  ><br>

Complete the information below <br></br>
<table>
<tr>
<td>Nombre &nbsp;</td> 
<td>
  <input name="nombre" value="<?php=$nombre?>" type="text" id="nombre" />&nbsp;
</td>
</tr>
</table>

The first <?php echo $nombre; ?> shows the correct value, but inside <input> tag it prints blankstring. What am I doing wrong?

1
  • 1
    Side note: You should do a htmlspecialchars() on $nombre if it's not already been run on it. Commented May 8, 2011 at 16:29

2 Answers 2

3

You have <?php=$nombre?> instead of <?=$nombre ?> or <?php echo $nombre ?> in your input tag.

Sign up to request clarification or add additional context in comments.

3 Comments

it mixes the short open tag convention with the full open tag convention.
this was one of the combinations. I have tried yours too, no success neither
@mujer then show the generated HTML so we don't have to guess.
2

I just tried the following code and it worked

<?php
$nombre = "hello"; 
?>

Let's edit  <?php echo $nombre; ?>.
<form action="getfile.php" method="post" name="uploadForm" id="uploadForm" enctype="multipart/form-data"  ><br>
Complete the information below <br></br>
    <table>
        <tr>
        <td>Nombre  &nbsp;</td> <td><input name="nombre" value="<?php echo $nombre?>" type="text" id="nombre" />&nbsp;</td>
        </tr></table>
</form>

1 Comment

I was not sending the right values,, and I realized thanks to you :) Sometimes it is necessary to start from the beggining

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.