19 thoughts on “PHP & MySQL Tutorial – 68: Creating a Signup Page

  1. <?php
    $host="localhost";
    $dbuser="root";
    $pass="";
    $dbname="mysite";
    $conn=mysqli_connect($host,$dbuser,$pass,$dbname);
    if(mysqli_connect_errno())
    {
    die("Connection Failed! " . mysqli_connect_error());
    }
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Abdibogoreh</title>
    </head>
    <body>
    <?php
    if(isset($_POST['submit']))
    {
    $first=$_POST['first_name'];
    $last=$_POST['last_name'];
    $email=$_POST['email'];
    $year=$_POST['year'];
    $month=$_POST['month'];
    $gender=$_POST['gender'];
    $pass=$_POST['pass'];
    $day=$_POST['day'];
    $dob=$year.'/'.$month.'/'.$day;
    $name=$first.' '.$last;
    $repass=$_POST['repass'];
    if(empty($first)||empty($last)||empty($email)||empty($year)||empty($month)||empty($day)||empty(($gender)||empty($pass)||empty($pass))
    {
    echo "Oops! can't leave any field blank!";
    } }
    elseif($pass!=$repass)
    {
    echo "Passwords didn't match! Please try again.";
    }
    else
    {
    $sql="INSERT INTO user (first,last,dob,gender,pass) " . "VALUES('$first','$last','$email','$dob','$gender','$pass')";
    $res=mysqli_query($conn,$sql);
    if(!$res)
    {
    die("Query Failed! " . mysqli_error($conn));
    }
    else
    {
    echo "Data inserted successfully!";
    }
    }
    else
    {
    echo "Form not submitted Properly!";
    }
    ?>

    </body>
    </html>

  2. <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Signup Page</title>
    </head>
    <body>
    <table cellspacing="15px" border="0px">
    <form action="signup_destination.php" method="POST">
    <tr>
    <td>First Name</td>
    <td><input type="text" name="first_name" /></td>
    </tr>
    <tr>
    <td>Last Name</td>
    <td><input type="text" name="last_name" /></td>
    </tr>
    <tr>
    <td>Email</td>
    <td><input type="text" name="email" /></td>
    </tr>
    <tr>
    <td>Date of Birth</td>
    <td><select name="year">
    <option>Year</option>
    <option>1985</option>
    <option>1986</option>
    <option>1987</option>
    <option>1988</option>
    <option>1989</option>
    </select>
    <select name="month">
    <option>Month</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    </select>
    <select name="day">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>
    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    </select></td>
    </tr>
    <tr>
    <td>Gender</td>
    <td>
    <input type="radio" name="gender" value="male" />Male
    <input type="radio" name="gender" value="female" />Female</td>
    </tr>
    </tr>
    <td>Password</td>
    <td><input type="password" name="pass" /></td>
    </tr>
    <tr>
    <td>Retype Password</td>
    <td><input type="password" name="repass" /></td>
    </tr>
    <tr>
    <td><input type="submit" name="submit" value="submit"/></td>
    </tr>
    </body>
    </html>

  3. 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";
    }
    }
    }

    ?>

  4. 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

Your email address will not be published. Required fields are marked *