0

When I try to register as a user, why won't my register.php file do anything? Am I missing something? I already made sure I am connected to the mysql database using the config.db

My registration page:

<html>
<head>
<title> Register!</title>
</head>
<body>
    <form action="register.php" method="POST">

            <h1>Signup!</h1>            

                <p>Create an account:</p>

                <div>
                    <label for="name">Name:</label>
                    <input type="text" id="name" name="firstname" value="" placeholder="First Name" class="login" />
                </div> <!-- /field -->

                <div>
                    <label for="email">Email Address:</label>
                    <input type="text" id="email" name="email" value="" placeholder="Email" class="login"/>
                </div> <!-- /field -->

                <div>
                    <label for="pass">Password:</label>
                    <input type="password" id="password" name="password" value="" placeholder="Password" class="login"/>
                </div> <!-- /field -->

                <div>
                    <label for="confirm_password">Confirm Password:</label>
                    <input type="password" id="confirmpassword" name="confirm_password" value="" placeholder="Confirm Password" class="login"/>
                </div> <!-- /field -->

                <input type="submit">Register</button>      
        </form>
    </div> <!-- /content -->

</div> <!-- /account-container -->
</body>

</html>

My php file

<?php

include ("configdb.php");

function createUser()
{
    $name = $_POST['name'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $confirmpassword = $_POST['confirmpassword'];

    echo "name";    
    if($password == $confirmpassword)
    {
        $query = "INSERT INTO Users (name,email,password) VALUES ('$name','$email','$password')";
        $data = mysql_query ($query)or die(mysql_error()); 
        if($data) 
        {
            echo "YOUR REGISTRATION IS COMPLETED..."; 
        }
    }
    else
    {
        echo "Passwords do not match";
        }
}


if(isset($_POST['submit']))
{
    createUser();
}
?>  
neminem
  • 2,658
  • 5
  • 27
  • 36
  • 10
    [Please, don't use `mysql_*` functions in new code](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). **You are also wide open to [SQL injections](http://stackoverflow.com/q/60174)** – John Conde Jul 21 '14 at 16:09
  • 5
    Please, [learn PDO](http://php.net/pdo) before it is too late, I can' `syntax error near 't stress this enough'` – Niet the Dark Absol Jul 21 '14 at 16:09
  • 1
    Your code is dependant on the conditional statement looking for a named form element, mainly your submit button which is malformed and should read as `` - Adding error reporting to the top of your file(s) `error_reporting(E_ALL); ini_set('display_errors', 1);` would've most likely caught that. – Funk Forty Niner Jul 21 '14 at 16:11
  • Did u find the inserted value in the database or the echo that u made – George Jul 21 '14 at 16:14

1 Answers1

11

Try giving your button a name.

<input type="submit" name="submit" value="Register">

When you post information through a form, you can call specific inputs by their name.

In this case you're looking for a set input field called 'submit':

isset($_POST['submit'])

But you have not given any inputs that specific name, when you click the submit button you are posting it, if you give it the name 'submit' then you are posting it through as 'submit', meaning when you check to see if 'submit' is posted, you get a response.

Mark
  • 1,852
  • 3
  • 18
  • 31