Page 1 of 1

Output from variables to table data

Posted: Fri Mar 26, 2004 8:21 am
by Xeal
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!

Posted: Fri Mar 26, 2004 12:04 pm
by TheBentinel.com
I am not sure what you are trying to do. Could you show an example of the HTML you'd like your PHP script to output?

Re: Output from variables to table data

Posted: Fri Mar 26, 2004 12:53 pm
by Chambrln
You need to change your echo to include a row and a cell to be included in your table.
Xeal 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>
Try something like this

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>