Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Björn Norén
Björn Norén
9,569 Points

Add multiple users

Hi, I'm trying to build a web-hotel and I have come this far: http://studenter.miun.se/~bjno1501/dt057g/webbutveckling2/php/practise/request.php

My next step is to add multiple users and I want to come next to each others from the top to bottom, like: "Mikael" "Andrew" "Jessica" and so on.

I guess I'm supposed to use a =+ symbol maybe, is there anyone who knows? Thank you everyone :)

I apologise for my english, my native language is Swedish. And bugs me that the code won't as it should now when I posts it.. Here is the code:

Request.php

<html>
<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  Name: <input type="text" name="fname">
  <input type="submit">
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // collect value of input field
    $name = $_REQUEST['fname'];
    if (empty($name)) {
        echo "Name is empty";
    } else {
        echo"<p> $name <a href='includes/log-out.php'>Delete</a></p>";
    }
}
?>

</body>
</html>

log-out.php
<?php
session_start();
session_destroy();
header("location:../request.php");

?>

1 Answer

With PHP, my best assertion is that you'd need to store the array data in a database and use SQL to reference the stored data.

Then call the data from the database, e.g.:

<?php
//after fetching the $_POST value, this would call the additional names you have stored
$query = "SELECT first_name FROM names;";
$result = mysqli_query($db_connection, $query);
$row = mysqli_fetch_array($result);
$fname = $row['first_name'];

foreach ($fname as $name) {
 echo"<p> $name <a href='includes/log-out.php'>Delete</a></p>";
}
?>

Probably something in that area.