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.