-1

I'm trying to create a registration form for my users. I have created the PHP as follows:

<?php

define('DB_HOST', 'mysql7.000webhost.com');
define('DB_NAME', ' <M PUTTING DATABASE USERNAME HERE> ');
define('DB_USER','<IM PUTTING USERNAME HERE>');
define('DB_PASSWORD','<M PUTTING PASSWORD HERE>');

$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error());


function NewUser()
{
    $username= $_POST['username'];
    $email = $_POST['email'];
    $password =  $_POST['password'];
    $query = "INSERT INTO members (username,email,password) VALUES ('$username','$email','$password')";
    $data = mysql_query ($query)or die(mysql_error());
    if($data)
    {
    echo "YOUR REGISTRATION IS COMPLETED...";
    }
}

function SignUp()
{
if(!empty($_POST['username']))   //checking the 'user' name which is from Sign-Up.html, is it empty or have some text
{
    $query = mysql_query("SELECT * FROM members WHERE username = '$_POST[username]' AND password = '$_POST[password]'") or die(mysql_error());

    if(!$row = mysql_fetch_array($query) or die(mysql_error()))
    {
        newuser();
    }
    else
    {
        echo "SORRY...YOU ARE ALREADY REGISTERED USER...";
    }
}
}
if(isset($_POST['submit']))
{
    SignUp();
}
?>

Here is my HTML UI page

<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script> 
$(function(){
});
  $("#header").load("header.html"); 
  $("#footer").load("footer.html"); 
</script> 
<title>Mases Krikorian Website</title>
<link rel="stylesheet" type="text/css" href="index.css">
<link rel="stylesheet" type="text/css" href="login.css">
<style>
h2{
font-family: "Arial Black", Gadget, sans-serif;
}
td{
padding-left: 5px;
padding-right: 5px;
}
</style>
<div id="header"></div>
<div class="bgpic"></div>
</head>
<body>
<div class="container">
<div id="content">

<form method="POST" action="create.php">
<h1>Registration Form</h1>
            <div>
                <input type="username" placeholder="Username" required="" id="username" />
            </div>
                        <div>
                                 <input type="password" placeholder="Password" required="" id="password" />

                        </div>
            <div>
                <input type="email" placeholder="Email" required="" id="email" />
            </div>

                         <div>
            </div>

            <div>
                <input id="submit" type="submit" name="submit" value="Sign Up">

            </div>
</form><!-- form -->





</div>
</div>
</body>
<div id="footer"></div> 

Please note that I do not have any database issues, my main problem is that my username variables are returning blank if i remove the checking for empty functions. Also, the UI page is name create.html, and php page is name create.php, and table name is members. Any help would be much appreciated.

Radon5K
  • 47
  • 1
  • 9
  • 2
    set `name` for your inputs not only `id` – nospor Jun 08 '16 at 10:33
  • Please dont use [the `mysql_` database extension](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), it is deprecated (gone for ever in PHP7) Specially if you are just learning PHP, spend your energies learning the `PDO` database extensions. [Start here](http://php.net/manual/en/book.pdo.php) its really pretty easy – RiggsFolly Jun 08 '16 at 10:33
  • Only inputs with a `name="something"` attribute are sent by the browser to the PHP script – RiggsFolly Jun 08 '16 at 10:34

2 Answers2

0

This is really so simple you will amaze now .

Change your code for Username and all

 <input type="username" placeholder="Username" required="" id="username" />

To

 <input type="text" name="username" placeholder="Username" required="" id="username" />

You might found two mess one you had used "username" in type which is not allowed also you did not have name attribute so it will not send its data to next php page.

I am sure you found your answer but please make changes to other two elements as mentioned above.

Recommend to user NETBEANS because it will show this types of errors and it will helpful.

Good Luck

khajaamin
  • 856
  • 7
  • 18
0
  1. Please double check this code

    $query = mysql_query("SELECT * FROM members WHERE username ='$_POST[username]' AND password = '$_POST[password]'") or die(mysql_error());
    
  2. In your 'create.php' file, double check this code

    newuser();
    
  3. In your .html file change these 3 lines

    <input type="username" placeholder="Username" required="" id="username" />
    
    <input type="password" placeholder="Password" required="" id="password" />
    
    <input type="email" placeholder="Email" required="" id="email" />
    

    to

    <input type="text" placeholder="Username" required="" id="username" name="username"/>
    
    <input type="password" placeholder="Password" required="" id="password" name="password"/>
    
    <input type="email" placeholder="Email" required="" id="email" name="email"/>
    
Xi WANG
  • 16
  • 1