Adding Users to SQL
Posted: Thu Apr 06, 2006 3:09 pm
I have this code to add new users to database on this server.
it seems to not be accessing it i keepgeting my registration failed
and when i login it says the username and password are not in database i have the correct login details i know this for sure as if i change the it says it cant connect.
hope someone can help
thanks in advance
reece
it seems to not be accessing it i keepgeting my registration failed
and when i login it says the username and password are not in database i have the correct login details i know this for sure as if i change the it says it cant connect.
Code: Select all
<?php
require_once('setup.php');
// Connect to the database
mysql_connect($server,$dbuser,$dbpass) or die ("Could not establish connection"); // make connection
mysql_select_db($dbname); // select database
// convert posted info to easy to use variables
$user = $_REQUEST['username'];//get username from form
$pass = $_REQUEST['password'];//get password from form
$email = $_REQUEST['email'];// get email from form
$biography = $_REQUEST['biography'];// get biography from form
// strip away any dangerous tags
$user=strip_tags($user);
$pass=strip_tags($pass);
$email=strip_tags($email);
$biography=strip_tags($biography);
// remove spaces from variables
$user=str_replace(" ","",$user);
$pass=str_replace(" ","",$pass);
$email=str_replace(" ","",$email);
// remove escaped spaces
$user=str_replace("%20","",$user);
$pass=str_replace("%20","",$pass);
$email=str_replace("%20","",$email);
// add slashes to stop hacking
$user=addslashes($user);
$pass=addslashes($pass);
$email=addslashes($email);
$biography=addslashes($biography);
// minimum lengths
$minuser_len = 4; //username minimum length
$minpass_len = 4; //password minimum length
if(strlen($user) < $minuser_len || strlen($pass) < $minpass_len)
{
die("User/password was not long enough!");
}
// hash users password for security (32 chars random - md5)
$pass=md5($pass);
// create the SQL query to be executed
$request = "INSERT INTO login ( `userid` , `username` , `password`) VALUES ('', '$user', '$pass');";
// execute the query
$result = mysql_query($request);
// check if succesful registration
if($result){
echo "Registration was succesful
<a href=\"showusers.php\">**** here to view user.</a>";
} else {
echo "Registration failed";
}
?>
hope someone can help
thanks in advance
reece