Hello, i wonder if anyone can help me figure this out. I'm pretty new to all this so please be gentle with me
I wrote a script which is puzzling me as it seems to be working but it isn't. I am trying to make sure a chosen username does'nt already exist in the database before actually inserting the required data to register for my site. My site is not actually live, i am just trying to teach myself how to do some web design and application development. I have a wampserver set up to test everything on.
The Script:
<?php
/**
* @author The Dark Fool
* @copyright 2008
*
* Registration Script
*
**/
/** Check the required fields from the form
(Javascript 'Liveforms' should have done this already, but double checking anyway just in case)**/
if ((!isset($_POST["username"])) || (!isset($_POST["password"])) || (!isset($_POST["birth_year"])) || (!isset($_POST["email"])) || (!isset($_POST["disclaimer"]))) {
header("Location: Register.php");
exit;
}
/** Include neccesary files **/
include 'Includes/Database.php';
$dbcxn;
/** Check that the username does not already exist. **/
$user = $_POST["username"];
$sql = "SELECT username FROM register WHERE username='$user'";
$res = mysql_query($dbcxn, $sql);
$num = mysql_num_rows($res); /** Result should not be greater than 0 **/
if ($res > 0) { /** Redirect to inform the user to choose another username**/
header("Location: Reg-UN-Exists.php");
}
else {
/** Set VALUE variables **/
$username = $_POST["username"];
$birth_year = $_POST["birth_year"];
$email = $_POST["email"];
$disclaimer = $_POST["disclaimer"];
$password = $_POST["password"];
/** Issue the instruction to the database **/
$register = "INSERT INTO register (username, birth_year, email, disclaimer, password)
VALUES ('$username', '$birth_year', '$email', '$disclaimer', md5($'password')";
$result = mysql_query($dbcxn, $register);
if ($register == TRUE) {
header("Location: Login.php");
}
}
mysql_close($dbcxn);
?>
Now as far as i know since i put it together in parts, the script makes sure the forms feilds are filled in (both client side javascript, and then server side) then i added the database include (this also seemed to work as no database was there at first, and then when it was there was no table) the errors reported this and so i figured this bit worked.
Now what puzzles me is that it seems to go through the motions and takes me to the login page, but upon checking the database nothing has been inserted at all.
As far as i know there are no errors in the script itself, like i say, it appears to work but doesn't so any help will be helpful as i get no errors saying parse error, or unexcted T variable. Just opens up the next step which is login. The login script isnt made yet, one thing at a time.
The form is an include file, and is running some javascript to validate it. The database info is also an include file.
Any help or suggestions is appreciated.
Thanks in advance.
Edit: The VALUE variables were added after i tried it for the first time thinking it might help, but it hasn't helped, and nor has it changed anything. I thought i'd at least get some error messages or something, but no. Puzzled and confused very much.





Bookmarks