如何在php中连接登录,注册和配置文件之间的页面

时间:2014-12-03 06:15:51

标签: php web connect

我仍然是php的新手,我想连接这三页。我想知道如何将数据从注册转移到pfofile以及登录页面。我试图使用标签,但没有工作。

页=注册

<body>
<?php
 // define variables and set to empty values
$email = $username = $name = $contact = $birthday = $gender = $address = $password = $payment           ="";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = test_input($_POST["email"]);
$username = test_input($_POST["username"]);
$name = test_input($_POST["name"]);
$contact = test_input($_POST["contact"]);
$birthday = test_input($_POST["birthday"]);
$gender = test_input($_POST["gender"]);
$address = test_input($_POST["address"]);
$password = test_input($_POST["password"]);
$payment = test_input($_POST["payment"]);
}

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
 }
 ?>
 <div id="login">
<form id="registeration" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<fieldset>
<legend><h1>Registeration</h1></legend>
 <p>Email:<br/>
 <input type="email" name="email"></p>
<p>Username:<br/>
  <input type="text" name="username" />
</p>
<p>Your Name:<br/>
<input type="text" name="name"/></p>
<p>Contact Number:<br/>
<input type="text" name="contact"/></p>
<p>Birthday:<br/>
 <input type="date" name="birthday">
 <p>Gender:<br/>
<input type="radio" name="gender" value="male"/>Male
<input type="radio" name="gender" value="female"/>Female
</p>
 <p>Address: <br/>
  <textarea name="address" cols="50"></textarea></p>  
<p>Password:<br/>
<input name="password" type="password" size="50"/></p>
</p>

<h2>Choose payment method:<br/></h2>
<p><input type="radio" name="payment" value="cod"/>CASH ON          DELIVERY</p>
<p><input type="radio" name="payment" value="Online Banking"/>ONLINE BANKING : CIMB Clicks<br/>
 <p><input type="radio" name="payment" value="Online Banking"/>ONLINE BANKING : Maybank<br/>
  <p><input type="radio" name="payment" value="Online Banking"/>ONLINE BANKING : BSN<br/>
<p><input type="radio" name="payment" value="atm"/>ATM</p>
<p><button type="submit" value="submit">Submit</button><span>    <span><span><span><span>
   <button type="reset" value="cancel">Cancel</button></p>
</fieldset>
 </form> 
 </div>

echo $email;
echo "<br>";
echo $username;
echo "<br>";
echo $name;
echo "<br>";
echo $contact;
echo "<br>";
echo $birthday;
echo "<br>";
echo $gender;
echo "<br>";
echo $address;
echo "<br>";
echo $password;
echo "<br>";
echo $payment;
    ?>

</body>

页=登入

<body>

<div id="login">
<fieldset>
 <legend><h1>Login</h1></legend>
 <form id="signin" method="POST">
 <p>Username:<br/>
 <input type="text" name="username"/></p>
 <p>Password:<br/>
 <input type="password" name="password"/></p>
 <p><button type="submit" value="submit">Submit</button><span>
 <button type="reset" value="cancel">Cancel</button></p>
 </form>
 </fieldset>
 <!-- end .content --></div>
  <?php
        error_reporting(0);
        if (!empty ($_POST)){
        if ($_POST ["username"] == NULL){
            echo "Please insert your username!";}
            else{
                $strusername=$_POST["username"];
                echo "<p>$strusername</p>";
            }}
            if (!empty ($_POST)){
        if ($_POST ["password"] == NULL){
            echo "Please insert the password!";}
            else {
                $strpassword=$_POST["password"];
                echo "<p>$strpassword</p>";
            }}
    ?>
        </body>

页=轮廓

<body>
<div class="container">
<div class="content">
<table>
<td colspan="5"><b>PROFILE</b></td>
 <tr>
<td><div align="left">Username:</div></td><td><?php echo $username ?></td></tr>
<td><div align="left">Name:</div></td><td><?php echo $name ?></td></tr>
<td><div align="left">Username:</div></td><td><?php echo $username ?></td></tr>
<td><div align="left">Birthday:</div></td><td><?php echo $birthday ?></td></tr>
<td><div align="left">Contact Number:</div></td><td><?php echo $contact ?></td></tr>
<td><div align="left">Gender:</div></td><td><?php echo $gender ?></td></tr>
<td><div align="left">Address:</div></td><td><?php echo $address ?></td></tr>
<td><div align="left">My payment Method:</div></td><td><?php echo $payment ?></td>          </tr>
<tr>
<td><div align="left"><button type="submit" value="Edit Profile" >Edit Profile</button></div>  </td>
</tr>
</table>
 <!-- end .content --></div>
 <!-- end .container --></div>
 </body>

3 个答案:

答案 0 :(得分:0)

好吧,尝试使用帖子并获取。

PHP superglobals $ _GET和$ _POST用于收集表单数据。下面的示例显示了一个简单的HTML表单,其中包含两个输入字段和一个提交按钮:

<html>
<body>

<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>

当用户填写上面的表单并单击提交按钮时,表单数据将被发送到名为&#34; welcome.php&#34;的PHP文件中。表单数据使用HTTP POST方法发送。

要显示提交的数据,您只需回显所有变量即可。 &#34; welcome.php&#34;看起来像这样:

<html>
<body>

Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

</body>
</html>

输出可能是这样的:

Welcome John
Your email address is john.doe@example.com

使用HTTP GET方法也可以实现相同的结果:

<html>
<body>

<form action="welcome_get.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>

和&#34; welcome_get.php&#34;看起来像这样:

<html>
<body>

Welcome <?php echo $_GET["name"]; ?><br>
Your email address is: <?php echo $_GET["email"]; ?>

</body>
</html>

我建议您按照本教程here 我希望它会帮助你,最好的问候

答案 1 :(得分:0)

使用$ _SESSION

在每个页面中以<?php session_start(); ?>

开头

然后存储$_SESSION['email'] = test_input($_POST["email"]);

然后在任何页面中,您都可以使用echo $_SESSION['email'];

答案 2 :(得分:0)

您应该使用SESSION进行简单的登录功能....

请参阅此tutorial有关基本登录和功能的信息