Adding Users to SQL

Any problem with PHP can be disscused here
Locked
reece
Posts: 55
Joined: Tue Apr 04, 2006 10:59 am

Adding Users to SQL

Post by reece »

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.

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


jasondsouza
Posts: 348
Joined: Thu Jan 12, 2006 8:24 pm
Contact:

Post by jasondsouza »

what is the actual error message
--jasondsouza
ME working on a very new site. (Coming soon)
Come to my web Site
reece
Posts: 55
Joined: Tue Apr 04, 2006 10:59 am

hi thanks

Post by reece »

hi thanks for you reply i have sorted it know thanks anyway
Locked