如何在 php 中存储用户信息,然后将其显示在表中


How to store user information in php and then display it in a table

我正在尝试创建一个登录凭据表。我有一个登录按钮,可以接受用户名和密码,并能够通过 POST 发送它们。我想在 html 表中显示信息。我的索引.html如下所示:

<html><head>
<title>Login</title>
</head>
<body style="left:-1px; top:-2px; " >
<form action="index.html" method="post" >
Email<input type="email" name="data" value="" />
Password<input type="text" name="pass" value="" />
<input type="submit" />
<?php 
$index = 0;
$credentials = array{usernames,};
if (isset($_POST['submit']) { //to check if the form was submitted
    $username= $_POST['data'];
     $password= $_Post['pass'];
    //$result = array($username,$password);
    $credentials['usernames'].append($username);
    $credentials['passwords'].append($password);

    }
?>

</form>
<table>
<tbody><tr><th>Usernames</th>
<th>Passwords</th>
<?php for($i = 0; $i < $credentials.length; $i++){ <tr><?php echo $credentials[i]?></tr><tr><?php echo $credentials[password[i]]?></tr><tr>
</body><html>

我做错了什么?

首先,表单操作指向一个 HTML 文件。如果您希望使用 PHP,请使用.php文件扩展名。这是你的第一个问题,就在那里。HTML 文件无法解析 PHP。

其次,如果你想解析密码,请谨慎使用PHP。然后,考虑一个 php while 循环来列出每个 $_POST,如下所示:

echo '<table>';
while (list($key,$value) = each($_POST)) {
    echo '<tr><td>'.$key.'</td><td>'.html_entity_decode(stripslashes($value)).'</td></td>';
}
echo '</table>';

无论表单中的项目数如何,您都应该能够正确查看信息。