我正在使用引导程序,我想使用php的登录/注册页面。我将index.html更改为index.php与register.php
和login.php
所以这是我login.php
文件中以前为login.html
的部分。
我有一个base.php
文件,其中包含我的数据库的信息。我可以使用数据库就好了,我用更简单的代码完成了它。
我的问题是:我是否在此页面中添加了php代码,我该怎么做?
<div class="sign-in-form-top">
<h1>Inicio de Sesión</h1>
</div>
<div class="signin">
<div class="signin-rit">
<span class="checkbox1">
<label class="checkbox"><input type="checkbox" name="checkbox" checked="">¿Olvidaste tu contraseña?</label>
</span>
<p><a href="#">Haz clic aquí</a> </p>
<div class="clearfix"> </div>
</div>
<form>
<div class="log-input">
<div class="log-input-left">
<input type="text" class="user" value="Tu Correo Electrónico" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Tu Correo Electrónico';}"/>
</div>
<span class="checkbox2">
<label class="checkbox"><input type="checkbox" name="checkbox" checked=""><i> </i></label>
</span>
<div class="clearfix"> </div>
</div>
<div class="log-input">
<div class="log-input-left">
<input type="password" class="lock" value="password" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email address:';}"/>
</div>
<span class="checkbox2">
<label class="checkbox"><input type="checkbox" name="checkbox" checked=""><i> </i></label>
</span>
<div class="clearfix"> </div>
</div>
<input type="submit" value="Inicia Sesión">
</form>
</div>
<div class="new_people">
<h2>¿Todavía no sos miembro?</h2>
<p>Crea tu cuenta, es fácil y rápido.</p>
<a href="register.php">¡Registrate Ahora!</a>
&#13;
答案 0 :(得分:0)
您可以使用PHP自我方法将表单发送到login.php本身。确保您的表单有行动和方法。
<?php
if(isset($_POST['login-form'])) {
// Your Code Here
}
?>
<html>
<body>
<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?> method="post" enctype="multipart/form-data" >
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<button type="submit" name="login-form"> Submit </button>
</form>
或者您可以将表单发送到另一个PHP文件。
答案 1 :(得分:0)
首先,你应该在互联网上搜索有很多教程可供登录和注册演示。
快速解决方案。
<?php
include('base.php');
session_start(); // Starting Session
$error=''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error = "Username or Password is invalid";
}
else
{
// Define $username and $password
$username=$_POST['username'];
$password=$_POST['password'];
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
// Selecting Database
$db = mysql_select_db("company", $connection); //$connection -> Connection of the database from base.php
// Assuming you have table LOGIN or Change the table name with your along with the database columns
// SQL query to fetch information of registerd users and finds user match.
$query = mysql_query("select * from login where password='$password' AND username='$username'", $connection);
$rows = mysql_num_rows($query);
if ($rows == 1) {
// Session to check whether the user is logged in or not in another pages
$_SESSION['login_user'] = $username; // Initializing Session
header("location: PageYouWantAfterLogin.php"); // Redirecting To Other Page
} else {
$error = "Username or Password is invalid";
}
mysql_close($connection); // Closing Connection
}
}
?>
请更改文本框的代码并提交按钮
<input type="text" name="username" class="user" value="Tu Correo Electrónico" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Tu Correo Electrónico';}"/>
<input type="password" name="password" class="lock" value="password" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email address:';}"/>
<input name="submit" type="submit" value=" Login ">
另外,将<form>
标记更改为以下代码。阅读有关表单here
<form action="" method="post">