Monday 30 September 2019

Step by Step guide to connect login page with database using HTML, CSS, PHP, MySQL


Problem statement:
 Design HTML pages for Registration/login and connect that pages with database also generate 
 several reports as per the application requirement in your project.
Objective:
 1. create login and registration page.
   1.1 when user enters username and password check either it is valid display the message login succesfull..or if not.
   1.2 if it is not valid store his information in database and make him valid and again perform the
         login if login successfull display the appropriate message login successfull.
Solution:
 A. First install XAMPP server on your machine as per the machine operating system and also
     download sublime Text editor. (Errors may be like this:>api-ms-win-crt-runtime-|1-1-0.dll
     reinstall)
 B. Start Apache and MySQL services.
 C. Go to browser and type localhost/phpmyadmin
 D. Create database eg:login after that Create table eg:users inside this database and insert
      one row value in it like testuser and password testuserpass.
 E. Create one folder inside C:/Program file/XAMPP --> htdoc ---> create your project folder like
      LoginProj
 F. inside this LoginProj folder store three files in it. 1.login.php 2. style.css  3.process.php
 G. Now inside login.php write the code of login form design with form action=process.php and
      method="POST"
 H. After that go to Browser and check either login form design is proper or not so for that type
      localhost/LoginProj/login.php.
 I. When we click on login button it take us to process.php page.
 J. Now go to style.css page and write all code neccessary for login form design.
 K. Now go to process.php page and write code
        //1.to get values passes from form in login.php file.
      <?php
         $username=$_POST['username']; //username must be id="username" value in login.php file
         $password=$_POST['password']; //password must be id="password" value in login.php file
       //2.to prevent mysql injection. Ref:https://www.youtube.com/watch?v=arqv2YVp_3E
         $username=stripcslashes($username);
         $password=stripcslashes($password);
         $username=mysql_real_escape_string($username);       
         $password=mysql_real_escape_string($password);
       //3.connect to the server and select database.
         mysql_connect("localhost","root","");
         mysql_select_db("login");
       //4.query the database for user.
        $result=mysql_query("select * from users where username = '$username' and password =
        '$password'") or die("Failed to query database" .mysql_error());
        $row = mysql_fetch_array($result);
        if($row['username']==$username && $row['password']==$password)
       {
         echo "Login success!!! Welcome".$row['username'];
       }
       else
       {
         echo "Failed to login...";
       }
     ?>
 L. Now go to browser and type localhost/LoginProj/login.php. enter user and password and click on login button appropriate message gets displayed.

/*HERE IS THE CODE FOR ALL PAGES*/ 

 1. login.php
 <html>
<head>
 <title> Login and Registration Form Design</title>
 <link rel="stylesheet" href="style.css">
</head>
<body>
 <div class="login-page">
 <div class="form">
  <form class="register-form">
  <input type="text" placeholder="username" name="useri" id="user"/>
  <input type="text" placeholder="password" name="pasw" id="pass"/>
  <input type="text" placeholder="email id" name="emaill" id="email"/>
  <button>Create</button>
  <p class="message"> Already Registered?<a href="#"> Login</a></p>
  </form>
  <form class="login-form" action="process.php" method="POST">
  <input type="text" placeholder="username" id="username" name="usr"/>
  <input type="password" placeholder="password" id="password" name="passw"/>
  <button>Login</button>
  <p class="message">Not Registered?<a href="#"> Register</a></p>
 </div>
 </div>
 <script src='https://code.jquery.com/jquery-3.4.1.min.js'>
 </script>
 <script>
  $('.message a').click(function(){
  $('form').animate({height:"toggle",opacity:"toggle"},"slow");
  });
 </script>

</body>
</html>


2. style.css 

body{
 background-image:linear-gradient(rgba(0,0,0,0.6),rgba(0,0,0,0.6)),url(Lighthouse.jpg);
 height:100vh;
 background-size:cover;
 background-position:center;
}
.login-page{
 width:360px;
 padding:10% 0 0;
 margin:auto;
}

.form{
 position:relative;
 z-index:1;
 background:rgba(7,40,195,0.8);
 max-width:360px;
 margin:0 auto 100px;
 padding:45px;
 text-align:center;
}

.form input{
 font family:"Roboto",sans-serif;
 outline:1;
 background:#f2f2f2;
 width:100%;
 border:0;
 margin:0 0 15px;
 padding:15px;
 box-sizing:border-box;
 font-size:14px;
}

.form button{
 font family:"Roboto",sans-serif;
 text-transform:uppercase;
 outline:0;
 background:#4cAF50;
 width:100%;
 border:0;
 padding:15px;
 color:#ffffff;
 font-size:14px;
 cursor:pointer;
}

.form button:hover,.form button:active{
 background:#43A047;
}

.form .message{
 margin:15px 0 0;
 color:aliceblue;
 font-size:12px;
}

.form .message a{
 color:#4CAF50;
 text-decoration:none;
}

.form .register-form{
 display:none;
}

3. process.php

<?php
        $con=mysqli_connect("localhost","root","","login");
        // Check connection
           if (mysqli_connect_errno()) {
           echo "Failed to connect to MySQL: " . mysqli_connect_error();
          }
          // escape variables for security
          $uname = mysqli_real_escape_string($con, $_POST['usr']);
          $password = mysqli_real_escape_string($con, $_POST['passw']);

         //query to the database

          $sql="select * from users where username = '$uname' and password = '$password'";
          $result=mysqli_query($con,$sql);

          if (!mysqli_query($con,$sql)) {
              die('Error: ' . mysqli_error($con));
              }
              else
              {

                $row=mysqli_fetch_array($result,MYSQLI_ASSOC);

                if($row['username']==$uname && $row['password']==$password)
                {
                 echo "Login success!!! Welcome ".$row['username'];
                }
                else
                {
                 echo "Failed to login...";
                }

              }

            mysqli_close($con);      
     ?>



 
data structures and algorithms Web Developer

Tuesday 13 August 2019

SE COMP A.Y 2019-20 GROUP B CINEMAX ASSIGNMENT MODIFIED


//============================================================================
// Name        : cinemax.cpp
// Author      : NitinShivale
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

class cinemax
{
    cinemax *next;
    cinemax *prev;
    cinemax *rows[10];  //data members
    string mname;
    long mobno;
    int flag;
    int seatno;
public:
    cinemax() //constructor..to initialize the data memeber and rows array.
    {
     flag=0;
     mobno=0;
     seatno=0;
     next=prev=NULL;
     for(int i=0;i<10;i++)
     {
       rows[i]=NULL;
     }
    }
    void show();
    void showSeat();        //member Functions
    void createTheater();
}; //end of class

//This show() function only displays the status of rows i:e Array of pointer.
void cinemax::show()
{
 for(int i=0;i<10;i++)
 {
  cout<<"|"<<rows[i]<<"|-> "<<"\n\n";
 }
}

//This showSeat() function displays the memory map of theater after creation of theater...
void cinemax::showSeat()
{
 cinemax *temp;
 for(int i=0;i<10;i++)
 {
  cout<<"|"<<rows[i]<<"|-> ";
  temp=rows[i];
  for(int j=0;j<7;j++)
  {
   cout<<"|"<<temp->prev<<"|"<<temp->seatno<<"|"<<temp->flag<<"|"<<temp->mname<<"|"<<temp->mobno<<"|"<<temp->next<<"|<-->";
   temp=temp->next;
  }
  cout<<"\n\n";
 }
}

//This createTheater() function creates the 10 rows and 7 seats of Theater by using Doubly Circular Linked List.
void cinemax::createTheater()
{
    cinemax *p,*temp,*head,*p1;
    head=p=p1=temp=NULL;
    int i,j;
    //code for to create the ten rows....

    for(i=0;i<10;i++)
    {
     p=new cinemax;
     p->flag=0;
     p->seatno=1;
     p->mname="NULL"; //code belongs to first node of each row
     p->mobno=0;
     p->next=p;
     p->prev=p;
     rows[i]=p;
     temp=p;
     head=temp;
     //code for to create six seats....
     for(j=1;j<7;j++)
     {
      p1=new cinemax;
      p1->flag=0;
      p1->seatno=j+1;
      p1->mname="NULL"; //assuming that flag zero, mob no zero and movie name i:e mname NULL means seat is not booked yet..initial state of seat.
      p1->mobno=0;
      p1->next=temp->next;
      p1->prev=temp;
      temp->next=p1;
      head->prev=p1;
      temp=p1;
     }
    }
}

//The program execution starts from main() function.
int main() {
    cout << "!!!Welcome To Cinemax Theater!!!" << endl;
    cinemax c1; //object c1 creation of cinemax theater to call all the member functions.
    int ch;
    do
    {
        cout<<"1.Show Rows Status Before Creation of Theater\n"; //Menu for user to display and operate accordingly..
        cout<<"2.Show Rows Status After Creation of Theater\n";
        cout<<"3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:\n";
        cout<<"4.Show Seat Vacancy in Theater...\n";
        cout<<"5.Book My Show..\n";
        cout<<"6.Cancel My Show...\n";
        cout<<"\nEnter your Choice...: ";
        cin>>ch;
        switch(ch)
        {
         case 1:cout<<"\n\nBefore Creation of Theater...\n";
                c1.show();
                break;
         case 2:c1.createTheater(); //member function calling
                cout<<"\n\nAfter Theater Creation...\n";
                c1.show();
                break;
         case 3:cout<<"\n After Seat creation of Theater....\n";
                c1.showSeat();
                break;
         case 4:cout<<"/* under process */\n";break;
         case 5:cout<<"/* under process */\n";break;
         case 6:cout<<"/* under process */\n";break;
        }//end of switch case

    }while(ch!=7); //end of do while loop.
    cout<<"\n\n Thank You so much Visit Again....\n";
 return 0;
}//end of main() function


/** ========  OUTPUT OF CINEMAX THEATER  =======================
 *!!!Welcome To Cinemax Theater!!!
1.Show Rows Status Before Creation of Theater
2.Show Rows Status After Creation of Theater
3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:
4.Show Seat Vacancy in Theater...
5.Book My Show..
6.Cancel My Show...

Enter your Choice...: 1


Before Creation of Theater...
|0|->

|0|->

|0|->

|0|->

|0|->

|0|->

|0|->

|0|->

|0|->

|0|->

1.Show Rows Status Before Creation of Theater
2.Show Rows Status After Creation of Theater
3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:
4.Show Seat Vacancy in Theater...
5.Book My Show..
6.Cancel My Show...

Enter your Choice...:2

After Theater Creation...
|0xd48010|->

|0xd484e0|->

|0xd489b0|->

|0xd48e80|->

|0xd49350|->

|0xd49820|->

|0xd49cf0|->

|0xd4a1c0|->

|0xd4a690|->

|0xd4ab60|->

1.Show Rows Status Before Creation of Theater
2.Show Rows Status After Creation of Theater
3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:
4.Show Seat Vacancy in Theater...
5.Book My Show..
6.Cancel My Show...

Enter your Choice...: 3

Enter your Choice...: 3

 After Seat creation of Theater....
|0xd48010|-> |0xd48430|1|0|NULL|0|0xd480c0|<-->|0xd48010|2|0|NULL|0|0xd48170|<-->|0xd480c0|3|0|NULL|0|0xd48220|<-->|0xd48170|4|0|NULL|0|0xd482d0|<-->|0xd48220|5|0|NULL|0|0xd48380|<-->|0xd482d0|6|0|NULL|0|0xd48430|<-->|0xd48380|7|0|NULL|0|0xd48010|<-->

|0xd484e0|-> |0xd48900|1|0|NULL|0|0xd48590|<-->|0xd484e0|2|0|NULL|0|0xd48640|<-->|0xd48590|3|0|NULL|0|0xd486f0|<-->|0xd48640|4|0|NULL|0|0xd487a0|<-->|0xd486f0|5|0|NULL|0|0xd48850|<-->|0xd487a0|6|0|NULL|0|0xd48900|<-->|0xd48850|7|0|NULL|0|0xd484e0|<-->

|0xd489b0|-> |0xd48dd0|1|0|NULL|0|0xd48a60|<-->|0xd489b0|2|0|NULL|0|0xd48b10|<-->|0xd48a60|3|0|NULL|0|0xd48bc0|<-->|0xd48b10|4|0|NULL|0|0xd48c70|<-->|0xd48bc0|5|0|NULL|0|0xd48d20|<-->|0xd48c70|6|0|NULL|0|0xd48dd0|<-->|0xd48d20|7|0|NULL|0|0xd489b0|<-->

|0xd48e80|-> |0xd492a0|1|0|NULL|0|0xd48f30|<-->|0xd48e80|2|0|NULL|0|0xd48fe0|<-->|0xd48f30|3|0|NULL|0|0xd49090|<-->|0xd48fe0|4|0|NULL|0|0xd49140|<-->|0xd49090|5|0|NULL|0|0xd491f0|<-->|0xd49140|6|0|NULL|0|0xd492a0|<-->|0xd491f0|7|0|NULL|0|0xd48e80|<-->

|0xd49350|-> |0xd49770|1|0|NULL|0|0xd49400|<-->|0xd49350|2|0|NULL|0|0xd494b0|<-->|0xd49400|3|0|NULL|0|0xd49560|<-->|0xd494b0|4|0|NULL|0|0xd49610|<-->|0xd49560|5|0|NULL|0|0xd496c0|<-->|0xd49610|6|0|NULL|0|0xd49770|<-->|0xd496c0|7|0|NULL|0|0xd49350|<-->

|0xd49820|-> |0xd49c40|1|0|NULL|0|0xd498d0|<-->|0xd49820|2|0|NULL|0|0xd49980|<-->|0xd498d0|3|0|NULL|0|0xd49a30|<-->|0xd49980|4|0|NULL|0|0xd49ae0|<-->|0xd49a30|5|0|NULL|0|0xd49b90|<-->|0xd49ae0|6|0|NULL|0|0xd49c40|<-->|0xd49b90|7|0|NULL|0|0xd49820|<-->

|0xd49cf0|-> |0xd4a110|1|0|NULL|0|0xd49da0|<-->|0xd49cf0|2|0|NULL|0|0xd49e50|<-->|0xd49da0|3|0|NULL|0|0xd49f00|<-->|0xd49e50|4|0|NULL|0|0xd49fb0|<-->|0xd49f00|5|0|NULL|0|0xd4a060|<-->|0xd49fb0|6|0|NULL|0|0xd4a110|<-->|0xd4a060|7|0|NULL|0|0xd49cf0|<-->

|0xd4a1c0|-> |0xd4a5e0|1|0|NULL|0|0xd4a270|<-->|0xd4a1c0|2|0|NULL|0|0xd4a320|<-->|0xd4a270|3|0|NULL|0|0xd4a3d0|<-->|0xd4a320|4|0|NULL|0|0xd4a480|<-->|0xd4a3d0|5|0|NULL|0|0xd4a530|<-->|0xd4a480|6|0|NULL|0|0xd4a5e0|<-->|0xd4a530|7|0|NULL|0|0xd4a1c0|<-->

|0xd4a690|-> |0xd4aab0|1|0|NULL|0|0xd4a740|<-->|0xd4a690|2|0|NULL|0|0xd4a7f0|<-->|0xd4a740|3|0|NULL|0|0xd4a8a0|<-->|0xd4a7f0|4|0|NULL|0|0xd4a950|<-->|0xd4a8a0|5|0|NULL|0|0xd4aa00|<-->|0xd4a950|6|0|NULL|0|0xd4aab0|<-->|0xd4aa00|7|0|NULL|0|0xd4a690|<-->

|0xd4ab60|-> |0xd4af80|1|0|NULL|0|0xd4ac10|<-->|0xd4ab60|2|0|NULL|0|0xd4acc0|<-->|0xd4ac10|3|0|NULL|0|0xd4ad70|<-->|0xd4acc0|4|0|NULL|0|0xd4ae20|<-->|0xd4ad70|5|0|NULL|0|0xd4aed0|<-->|0xd4ae20|6|0|NULL|0|0xd4af80|<-->|0xd4aed0|7|0|NULL|0|0xd4ab60|<-->

1.Show Rows Status Before Creation of Theater
2.Show Rows Status After Creation of Theater
3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:
4.Show Seat Vacancy in Theater...
5.Book My Show..
6.Cancel My Show...

Enter your Choice...: 4

Enter your Choice...: 4
*** under process  ****
1.Show Rows Status Before Creation of Theater
2.Show Rows Status After Creation of Theater
3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:
4.Show Seat Vacancy in Theater...
5.Book My Show..
6.Cancel My Show...

Enter your Choice...: 5
*** under process  ****
1.Show Rows Status Before Creation of Theater
2.Show Rows Status After Creation of Theater
3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:
4.Show Seat Vacancy in Theater...
5.Book My Show..
6.Cancel My Show...

Enter your Choice...: 6
*** under process  ****
1.Show Rows Status Before Creation of Theater
2.Show Rows Status After Creation of Theater
3.Show Memory Map of Seats after Creation of 10 Rows and Seven Seats..:
4.Show Seat Vacancy in Theater...
5.Book My Show..
6.Cancel My Show...

Enter your Choice...: 7

Thank You so much Visit Again....

 *************************************************************************************************/

data structures and algorithms Web Developer