2017-07-14 15 views
-1

私はブートストラップを使用しています。私はログイン/登録ページをPHPで使用したいと思います。私はindex.htmlをindex.phpに変更しました。register.phplogin.phpログイン/登録ページの使用方法

これはlogin.htmlだった以前の私のlogin.phpファイルのセクションです。

私のデータベースの情報を持つbase.phpファイルがあります。私はデータベースをうまく使用することができます。私は単純なコードでそれをやっています。

私の質問はです。このページにPHPコードを追加してもよろしいですか?

<div class="sign-in-form-top"> 
 
\t <h1>Inicio de Sesión</h1> 
 
</div> 
 
<div class="signin"> 
 
\t <div class="signin-rit"> 
 
\t \t <span class="checkbox1"> 
 
\t \t \t <label class="checkbox"><input type="checkbox" name="checkbox" checked="">¿Olvidaste tu contraseña?</label> 
 
\t \t </span> 
 
\t \t <p><a href="#">Haz clic aquí</a> </p> 
 
\t \t <div class="clearfix"> </div> 
 
\t </div> 
 
\t <form> 
 
\t \t <div class="log-input"> 
 
\t \t \t <div class="log-input-left"> 
 
\t \t \t \t <input type="text" class="user" value="Tu Correo Electrónico" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Tu Correo Electrónico';}"/> 
 
\t \t \t </div> 
 
\t \t \t <span class="checkbox2"> 
 
\t \t \t \t <label class="checkbox"><input type="checkbox" name="checkbox" checked=""><i> </i></label> 
 
\t \t \t </span> 
 
\t \t \t <div class="clearfix"> </div> 
 
\t \t </div> 
 
\t \t <div class="log-input"> 
 
\t \t \t <div class="log-input-left"> 
 
\t \t \t \t <input type="password" class="lock" value="password" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email address:';}"/> 
 
\t \t \t </div> 
 
\t \t \t <span class="checkbox2"> 
 
\t \t \t \t <label class="checkbox"><input type="checkbox" name="checkbox" checked=""><i> </i></label> 
 
\t \t \t </span> 
 
\t \t \t <div class="clearfix"> </div> 
 
\t \t </div> 
 
\t \t <input type="submit" value="Inicia Sesión"> 
 
\t </form> \t 
 
</div> 
 
<div class="new_people"> 
 
\t <h2>¿Todavía no sos miembro?</h2> 
 
\t <p>Crea tu cuenta, es fácil y rápido.</p> 
 
\t <a href="register.php">¡Registrate Ahora!</a>

答えて

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>タグを変更してください。書式の詳細については、

<form action="" method="post"> 
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ファイルにフォームを送信することができます。

関連する問題