Hi!
I am trying to output data from a variable to a html table.
Here is the code anyway that takes the data from 3 html text fields and prints it out on the same page.
<html>
<head>
<body>
<?
if (isset($_POST['fnamn'])) {
echo "<table border=1> <tr> <td> Välkommen </td> </tr> </table>"
.$_POST['fnamn']."" .$_POST['enamn']. /* This line prints out the surname and last name of the person, I want this name into a html table data*/
"!<br>";
echo " Du gillar att ".$_POST['intresse'].""; // this into table as well
}
?>
<form action="sida1.php" method="post">
Förnamn: <input type="text" name="fnamn">
<br>
Efternamn: <input type="text" name="enamn">
<br>
Intresse: <input type="text" name="intresse">
<br>
<input type="submit" value="Ok!">
</form>
</body>
</head>
</html>
How should I change my program to do this?
Very thanks to anyone who can help me!
Output from variables to table data
Moderator: General Moderators
-
TheBentinel.com
- Forum Contributor
- Posts: 282
- Joined: Wed Mar 10, 2004 1:52 pm
- Location: Columbus, Ohio
Re: Output from variables to table data
You need to change your echo to include a row and a cell to be included in your table.
Try something like thisXeal wrote:<html>
<head>
<body>
<?
if (isset($_POST['fnamn'])) {
echo "<table border=1> <tr> <td> Välkommen </td> </tr> </table>"
.$_POST['fnamn']."" .$_POST['enamn']. /* This line prints out the surname and last name of the person, I want this name into a html table data*/
"!<br>";
echo " Du gillar att ".$_POST['intresse'].""; // this into table as well
}
?>
<form action="sida1.php" method="post">
Förnamn: <input type="text" name="fnamn">
<br>
Efternamn: <input type="text" name="enamn">
<br>
Intresse: <input type="text" name="intresse">
<br>
<input type="submit" value="Ok!">
</form>
</body>
</head>
</html>
Code: Select all
<html>
<head>
<body>
<table border=1>
<? if (isset($_POST['fnamn'])) { ?>
<tr>
<td>Välkommen</td>
</tr>
<tr>
<td><? echo $_POST['fnamn'] ." ". $_POST['enamn']; ?></td>
</tr>
<tr>
<td><? echo "Du gillar att ". $_POST['intresse']; ?></td>
</tr>
<? } ?>
<form action="sida1.php" method="post">
<tr>
<td>Förnamn: <input type="text" name="fnamn"></td>
</tr>
<tr>
<td>Efternamn: <input type="text" name="enamn"></td>
</tr>
<tr>
<td>Intresse: <input type="text" name="intresse"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Ok!"></td>
</tr>
</form>
</table>
</body>
</head>
</html>