Output from variables to table data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Xeal
Forum Newbie
Posts: 5
Joined: Thu Jan 29, 2004 1:46 am
Location: Sweden

Output from variables to table data

Post 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!
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post 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?
Chambrln
Forum Commoner
Posts: 43
Joined: Tue Dec 02, 2003 10:45 am
Location: Oregon

Re: Output from variables to table data

Post 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>
Post Reply