How to put the value of a Php variable inside the Input in html5

0

Good afternoon I need to make the value of the $ x variable appear inside the input item. below is the code. Thank you very much in advance.

<!DOCTYPE html>
<html>
<head>
	<title>Teste</title>
</head>
<body>

<form>

	<fieldset style="width: 650px">
		<legend>Cotação</legend>
		<br/>
		<table frame="border" style="text-align: left;">
			<tr>
				<div>
					<td width="25">
						<h4>Item</h4>
					</td>
				</div>
				
				<div>
					<td width="300">
						<h4>Descrição</h4>
					</td>
				</div>
				
				<div>
					<td width="25">
						<h4>QTD</h4>
					</td>
				</div>
				<td>
					<h4>Valor Unit</h4>
				</td>
				<td>
					<h4>Valor Total</h4>
				</td>
			</tr>
			
			<?php
			$x = 0;
				while ($x < 7)
				{	
						$x ++;	
						
						
						echo '
							<tr style="text-align: left;">
								<td>
									<input style="width: 25px" type="text" name="item" value="<?php echo $x ?>">
								</td>
								<td width="300">
									<input style="width: 300px" type="text" name="nome">
								</td>
								<td width="25" style="text-align: center;">
									<input style="width: 60px" type="number" name="quantidade">
								</td>
								<td>
									<input style="width: 120px" type="number" name="valorUnit">
								</td>
								<td>
									<input style="width: 120px" type="number" name="Valor">
								</td>
							</tr> ';
				};
				
			?>
		</table>
		<br/>
		<fieldset style="width: 638px">
		<br/>
			<input type="submit" name="Enviar" <?php echo "<h5>  Respondidos $x </5>" ?>
			<br/>
			<br/>
			
			
			
		<br/>
	</fieldset>
		
	</fieldset>
</form>
</body>
</html>
    
asked by anonymous 08.09.2017 / 20:11

1 answer

0

Within echo does not work <?php ?> , you can simply concatenate with . in

<input style="width: 25px" type="text" name="item" value="'.$x.'">

The complete code would look like:

<!DOCTYPE html>
<html>
<head>
    <title>Teste</title>
</head>
<body>

<form>

    <fieldset style="width: 650px">
        <legend>Cotação</legend>
        <br/>
        <table frame="border" style="text-align: left;">
            <tr>
                <div>
                    <td width="25">
                        <h4>Item</h4>
                    </td>
                </div>

                <div>
                    <td width="300">
                        <h4>Descrição</h4>
                    </td>
                </div>

                <div>
                    <td width="25">
                        <h4>QTD</h4>
                    </td>
                </div>
                <td>
                    <h4>Valor Unit</h4>
                </td>
                <td>
                    <h4>Valor Total</h4>
                </td>
            </tr>

            <?php
            $x = 0;
                while ($x < 7)
                {   
                        $x ++;  


                        echo '
                            <tr style="text-align: left;">
                                <td>
                                    <input style="width: 25px" type="text" name="item" value="'.$x.'">
                                </td>
                                <td width="300">
                                    <input style="width: 300px" type="text" name="nome">
                                </td>
                                <td width="25" style="text-align: center;">
                                    <input style="width: 60px" type="number" name="quantidade">
                                </td>
                                <td>
                                    <input style="width: 120px" type="number" name="valorUnit">
                                </td>
                                <td>
                                    <input style="width: 120px" type="number" name="Valor">
                                </td>
                            </tr> ';
                };

            ?>
        </table>
        <br/>
        <fieldset style="width: 638px">
        <br/>
            <input type="submit" name="Enviar" <?php echo "<h5>  Respondidos $x </5>" ?>
            <br/>
            <br/>



        <br/>
    </fieldset>

    </fieldset>
</form>
</body>
</html>
    
08.09.2017 / 20:24