Hi there, I have started learning mysql recently and just as an exercise i thought i would try my hand at building a basic registration system using javascript, php and mysql. its going pretty well but i have come to the point where i will require some help, when i click register it should send the imputed data to the php script with then inserts the data into the mysql table if it is not already there, but it will do none of this and i am out of idea’s as to why this is happening! Note i am using wamp but that shouldn’t make a difference?
mysql table
Javascript file - register.js
// Public variables.
public static var username : String = "";
public static var email : String = "";
public static var password : String = "";
//Private variables.
private var message : String = "";
private var URL : String = "http://localhost/Games/Project_x/register.php";
private var windowRect : Rect = Rect(0, 0, 250, 180);
function OnGUI ()
{
// Draw the Register window.
windowRect = GUI.Window(0, windowRect, RegisterWindow, "Register Account");
}
function RegisterWindow (windowID : int)
{
// Username
username = GUI.TextField (Rect (80, 20, 160, 20), username, 32);
GUI.Label(Rect(10, 20, 200, 30), "Username ");
// Email
email = GUI.TextField (Rect (80, 50, 160, 20), email, 32);
GUI.Label(Rect(10, 50, 200, 30), "Email ");
// Password
password = GUI.PasswordField (Rect (80, 80, 160, 20), password, "*"[0], 32);
GUI.Label(Rect(10, 80, 200, 30), "Password ");
// Messages
GUI.Label(Rect(10, 150, 200, 30), message);
if(GUI.Button(Rect(80, 110, 100, 30), "Register" ))
{
if(username == "" || email == "" || password == "")
{
message = "Error : Please complete all fields.";
}
if(username == username email == email password == password)
{
var form = new WWWForm();
form.AddField( "username", username );
form.AddField( "email", email );
form.AddField( "password", password );
var upload = new WWW(URL, form );
username = "";
email = "";
password = "";
}
}
GUI.DragWindow (Rect (0,0, 10000, 20));
}
and the php script called register.php
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("unity") or die(mysql_error());
$Username = $_POST['username'];
$Email = $_POST['email'];
$Password = $_POST['password'];
$check = mysql_query("SELECT * FROM members WHERE username='$Username'");
$rows = mysql_num_rows($check);
if($rows == 0)
{
mysql_query("INSERT INTO members (username, email, password)
VALUES ('$Username', '$Email', '$Password')
");
}
?>