简体   繁体   中英

How to get a login form to accept a new registrant userid and password that was submitted successfully?

This is my first time asking a question on here in a long time so my formatting might be a little off.

My login form will not accept a new user registration that was submitted even though it shows the message that the form was submitted successfully. When I check the database through phpmyadmin, there is no record of the new registrant. My code is below.

index.php

<!-- Modal -->
<a href="#" class="modal" id="modal-one" aria-hidden="true">
  </a>
  <div class="modal-dialog">
    <div class="modal-header">

      <a href="#" class="btn-close" aria-hidden="true">×</a>
    </div>
    <div class="modal-body">

    <div id="content">
        <ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
            <li class="active"><a href="#red" data-toggle="tab">LOGIN </a></li>
            <li><label>/</label></li>
            <li><a href="#orange" data-toggle="tab">SIGNUP</a></li>

        </ul>
        <div id="my-tab-content" class="tab-content">
            <div class="tab-pane active" id="red">
         <form action="main.php" method="post" id="formID1" class="formular">   
            <span class="err"><?php if(isset($_GET['$message'])){ echo $_GET['$message'];} if(isset($_GET['loginerr'])){ echo $_GET['loginerr'];}if(isset($_GET['herr1'])){ echo $_GET['herr1'];} ?><br></span><br>
            <div class="form-group">
    <input type="text" placeholder="EMAIL ADDRESSS" name="email" class="validate[required,custom[email]] form-control" id="usr1" >
    <span class="email"></span>
</div>
<div class="form-group">
    <input type="password" placeholder="PASSWORD" name="password" class="validate[required] form-control" id="pwd1">
     <span class="pass"></span>
</div>


<div class="form-group">
    <input type="submit" id="submit1" name="login" class="submit1 btn btn-info" value="LOGIN">
</div>
                 <div class="modal-footer">
      <a href="#modal-two">RESET YOUR PASSWORD</a>
    </div>
        </form>    </div>


            <div class="tab-pane" id="orange">
            <form action="main.php" method="post" id="formID2" class="formular">
                    <span class="err" id="a_err"><?php if(isset($_GET['$message'])){ echo $_GET['$message'];} ?><br></span><br>
                        <div class="form-group">
    <input type="text" placeholder="EMAIL ADDRESSS" name="s_email" class="validate[required,custom[email]] form-control" id="usr2" >
        <span class="email"></span>

</div>
<div class="form-group">
    <input type="password" placeholder="PASSWORD" name="s_password" class="validate[required] form-control" id="spwd">
         <span class="pass"></span>
</div>
<div class="form-group">
    <input type="password" placeholder="CONFIRM PASSWORD" name="confirm_password" class="form-control validate[required,equals[spwd]]" id="cpwd">
         <span class="rght"></span>
</div>

<div class="form-group">
    <input type="submit" id="submit2" name="s_submit" class="submit2 btn btn-info" value="CREATE YOUR ACCOUNT">
</div>
                 <div class="modal-footer">
                 BY CREATING AN ACCOUNT YOU ACKNOWLEDGE THAT YOU 
      <a href="#">ACCEPT THE TERMS & CONDITIONS</a>
    </div>

   </form>   
            </div>



        </div>
    </div>

    </div>

  </div>

sql file

CREATE TABLE IF NOT EXISTS `login` ( 
  `id` int(12) NOT NULL AUTO_INCREMENT,
  `email` varchar(55) NOT NULL,
  `password` varchar(55) NOT NULL,
  `confirm_password` varchar(55) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
--
-- Dumping data for table `login`
--

INSERT INTO `login` (`id`, `email`, `password`, `confirm_password`)

validation.js

function signup_validation()

{

    alert("helloooooooo");
    var usr=document.getElementById("usr2").value;
    alert($usr);
    var pwd=document.getElementById("spwd").value;
    var cpwd=document.getElementById("cpwd").value;
    var atpos = usr.indexOf("@");
    var dotpos = usr.lastIndexOf("."); 

    if(usr=="" || pwd=="" || cpwd=="" || pwd!=cpwd)
        { 
            document.getElementById("a_err").innerHTML="Please Fill All Fields";

            if(usr==""){

                document.getElementById("a_err").innerHTML="Please Enter User Name";

            }
            else if (atpos<1 || dotpos<atpos+2 || dotpos+2>=usr.length) {

                document.getElementById("js_error").innerHTML="Not a valid e-mail address";

             }
            else if(pwd==""){

                document.getElementById("a_err").innerHTML="Please Enter Email";

            }
            else if(cpwd==""){

                document.getElementById("a_err").innerHTML="Please Re-Enter password ";

            }

            else if(pwd!=cpwd){

                document.getElementById("a_err").innerHTML="Password Do Not Match";

            }
            return false;
        }
    else{
    document.getElementById("a_err").innerHTML="";
    return true;
    }

} 


function login_validation()
{

    var username=document.getElementById("usr1").value;
    //alert(username);
    var atpos1 = username.indexOf("@");
    var dotpos1 = username.lastIndexOf(".");

    var password=document.getElementById("pwd1").value;

    if(username=="" || password=="")
        { 
            document.getElementById("js_error1").innerHTML="Please Fill All Fields";

            if(username==""){

                document.getElementById("js_error1").innerHTML="Please Enter Your Email Id";

            }
            else if (atpos1<1 || dotpos1<atpos1+2 || dotpos1+2>=username.length) {

                document.getElementById("js_error1").innerHTML="Not a valid e-mail address";

             }
            else if(password==""){

                document.getElementById("js_error1").innerHTML="Please Enter Password.";

            }
            return false;
        }
    else{
    document.getElementById("js_error1").innerHTML="";
    return true;
    }
}

main.php

<?php 
include 'config.php'; 
session_start();
//echo "hii";
if(isset($_POST['s_submit'])){

    $email=$_POST['s_email'];
    //echo $email;
    $pass=$_POST['s_password'];

    $sql=mysqli_query($con,"INSERT INTO personal_info (`email`,`password`,`first_time_login`)VALUES('".$email."','".$pass."','0')");
    header('location:index.php?$message="form successfully submitted you can login"');
}

if(isset($_POST['login'])){

    $email=$_POST['email'];
    $pass=$_POST['password'];

    $q=mysqli_query($con,"SELECT * FROM personal_info WHERE email='".$email."' AND password='".$pass."' ");
    $row_fetch=mysqli_fetch_assoc($q);
    echo $row_fetch['first_name'];
    $count=mysqli_num_rows($q);
    if($count>0){
     $id=$row_fetch['id'];
     $_SESSION['id']=$id;
    //$id=mysqli_insert_id($conn);
               if($row_fetch['first_time_login']=="1")  
    {   
    header('location:index.php#');  
    }
        else{
            header('location:user.php');    
        }
    }
    else{
    header('location:index.php?loginerr="invalid user"');   
    }
}

mysqli_close($con);
?>

Your <form action="" method="post" id="formID2" class="formular"> particularly the action part must have the php file on where your post code is located at (if the php code is located on a separate file)

Example:

<form action="main.php" method="post" id="formID2" class="formular">

or

<form action="your_file_name.php" method="post" id="formID2" class="formular">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM