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

时间:2013-09-26 18:28:00

标签: php html login html-table credentials

我正在尝试创建一个登录凭据表。我有一个登录按钮,可以获取用户名和密码,并可以通过POST发送它们。我想在html表中显示信息。我的index.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>

我做错了什么?

1 个答案:

答案 0 :(得分:0)

首先,表单操作指向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>';

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

相关问题