PHP & MySQL Tutorial – 68: Creating a Signup Page




Thanks for watching! Check out my other tutorials at: https://www.youtube.com/user/madhurbhatia89?feature=guide.

Original source


20 responses to “PHP & MySQL Tutorial – 68: Creating a Signup Page”

  1. You are a wonderful tutor and I liked the way you have explained here. I am new to Php and I am in very beginner level. I created the file but unfortunately it doesn't work. Gives me following error
    "Query Failed!Column count doesn't match value count at row 1"

    I did this almost everything based on this. If possible, would you please look on to this. Let me post my file codes here HTML and Php
    My HTML File with forms here.

    <div="container">
    <div="row">
    <div class="col-md-5">
    <a href="index.php"><h1>MyRoar</h1></a>

    </div>
    </div>
    </div>

    <div="container">
    <div="row">
    <div class="col-md-12">
    <div class="well well-lg">
    <h1>Register Here</h1>

    <div class='container'> <div class='container-fluid'> <div class='well'>
    <form class='form-horizontal' action='register_success.php' method='POST'>

    <div class='form-group'>
    <label class='control-label col-sm-3' for='first'> First Name:</label>
    <div class='col-sm-9'>
    <input type='text' name= 'first_name' class='form-control' id='firstname' placeholder='First Name'>
    </div>
    </div>

    <div class='form-group'>
    <label class='control-label col-sm-3' for='first'> Last Name:</label>
    <div class='col-sm-9'>
    <input type='text' name= 'last_name' class='form-control' id='firstname' placeholder='First Name'>
    </div>
    </div>

    <div class='form-group'>
    <label class='control-label col-sm-3' for='first'> Enter Email Address:</label>
    <div class='col-sm-9'>
    <input type='email' name= 'email' class='form-control' id='first' placeholder='Email Address'>
    </div>
    </div>

    <div class='form-group'>
    <label class='control-label col-sm-3' for='first'> Gender:</label>
    <label class='control-label col-sm-1' for='male'> Male</label>
    <div class='col-sm-3'>
    <input type='radio' name= 'gender' value='male' class='form-control' > </div>
    <label class='control-label col-sm-1' for='female'> Female</label>
    <div class='col-sm-3'>
    <input type='radio' name= 'gender' value='female' class='form-control' > </div>
    </div>

    <div class='form-group'>
    <label class='control-label col-sm-3' for='pwd'> Enter Password:</label>
    <div class='col-sm-9'>
    <input type='password' name= 'password' class='form-control' id='pwd' placeholder='Password'>
    </div>
    </div>

    <div class='form-group'>
    <label class='control-label col-sm-3' for='pwd'> Confirm Password:</label>
    <div class='col-sm-9'>
    <input type='password' name= 'confirm_password' class='form-control' id='pwd' placeholder='Confirm Password'>
    </div>
    </div>

    <div class='form-group'>
    <label class='control-label col-sm-3' for='first'> Country living in:</label>
    <div class='col-sm-9'>
    <input type='text' name= 'country' class='form-control' id='lastname' placeholder='Country'>
    </div>
    </div>

    <div class='form-group'>
    <label class='control-label col-sm-3' for='first'> Phone Number With Area Code:</label>
    <div class='col-sm-9'>
    <input type='tel' name= 'phonenumber' class='form-control' id='lastname' placeholder='Phone Number'>
    </div>
    </div>

    <div class='form-group'>
    <div class='col-sm-offset-2 col-sm-10'>
    <button type='submit' id='signupbtn' class='btn btn-success'>Submit</button>
    </div>
    </div>
    </form>
    </div>
    </div>
    </div>

    </div>
    </div>
    </div>
    </div>

    Then my Php Files with Php codes in here

    <?php
    include 'header.php';

    ?>

    <?php

    $host ="localhost";
    $dbuser="root";
    $pass="";
    $dbname="test";
    $conn=mysqli_connect($host, $dbuser, $pass, $dbname);
    if (mysqli_connect_errno()) {
    die ("Connection Failed". mysqli_connect_errno());
    }

    ?>
    <?php

    if (isset($_POST['submit']));{
    $first=$_POST['first_name'];
    $last=$_POST['last_name'];
    $email=$_POST['email'];
    $gender=$_POST['gender'];
    $password=$_POST['password'];
    $name=$first.$last;
    $repass=$_POST['confirm_password'];
    if (empty($first)){
    echo "Please Fill in All the Fields";
    }

    if (empty($last)){
    echo "Please Fill in All the Fields";
    }
    if (empty($email)){
    echo "Please Fill in All the Fields";
    }
    if (empty($gender)){
    echo "Please Fill in All the Fields";
    }
    if (empty($password)){
    echo "Please Fill in All the Fields";
    }

    if (empty($password)){
    echo "Please Fill in All the Fields";
    }

    elseif ($password!=$repass) {
    echo "Passwords didn't match, please try again.";

    }
    else {
    $sql="INSERT INTO users(FirstName, LastName, email, gender,password, country, Phonenumber)".
    "VALUES ('$first', '$last', '$email', '$gender', '$password')";
    $result=mysqli_query($conn, $sql);
    if (!$result){
    die ("Query Failed!". mysqli_error($conn));

    }
    else {
    echo "You are almost there, upload your resume";
    }
    }
    }

    ?>

  2. help! i keep getting server error 500.

    <html >
    <head>
    <meta charset="UTF-8">
    <title>background</title>

    <link rel="stylesheet" href="css/style.css">
    <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

    <script src="js/index.js"></script>

    </head>

    <body>

    <div class="container demo-1">

    <div class="content">

    <div id="large-header" class="large-header" style="height: 760px;">

    <form method="POST" action="" >
    <div class="box">

    <h1 id="logintoregister">Login</h1>

    <div class="group show">
    <input class="inputMaterial" type="text" name="FirstName" required>
    <span class="highlight"></span>
    <span class="bar"></span>
    <label>First Name</label>
    </div>
    <div class="group show">
    <input class="inputMaterial" type="text" name="Surname" required>
    <span class="highlight"></span>
    <span class="bar"></span>
    <label>Surname</label>
    </div>

    <div class="group ">
    <input class="inputMaterial" type="text" name="Email" required>
    <span class="highlight"></span>
    <span class="bar"></span>
    <label>Email</label>
    </div>

    <div class="group">
    <input class="inputMaterial" type="password" id="password" name="Password" required>
    <span class="highlight"></span>
    <span class="bar"></span>
    <label>Password</label>
    </div>
    <div class="group show">
    <input class="inputMaterial" type="password" id="confirm_password" required>
    <span class="highlight"></span>
    <span class="bar"></span>
    <label>Confirm Password</label>
    </div>

    <button ><input id="buttonlogintoregister" type = "submit" value="submit" name="submit">Login</button>
    <p id="plogintoregister">By registering, You accept all terms and conditons </p><p id="textchange" onclick="register()"> Sign Up</p>

    </form>

    <?php

    $host="xxx";
    $dbuser="xxx";
    $pass="xxx";
    $dbname="xxx";
    $conn=mysqli_connect($host, $dbuser, $pass, $dbname);
    if(mysqli_connect_errno())
    {
    die("connection Fails" . mysqli_connect_error());
    }

    if(isset($_POST['submit'] && !empty($_POST['submit']))

    {

    $FirstName=$_POST['FirstName'];
    $Surname=$_POST['Surname'];
    $Email=$_POST['Email'];
    $Password=$_POST['Password'];

    $sql="INSERT INTO Users(FirstName,Surname,Email,Password)" .
    "VALUES($FirstName','$Surname','$Email','$Password')";
    $res=mysqli_query($conn, $sql);
    if(!$res)
    {
    die("Query Failed! " . mysqli_error($conn));

    }
    else
    {

    echo "Data inserted successfully!";

    }

    }
    mysql_close();
    ?>

    <!– Related demos –>

    </body>
    </html>

Leave a Reply