# login script

**URL:** <https://www.phphelp.com/t/login-script/11137>\
**Category:** Beginners - Learning PHP\
**Created:** [April 4, 2008, 3:12am UTC](https://www.phphelp.com/t/login-script/11137 "2008-04-04T03:12:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![juanpab2](https://www.phphelp.com/letter_avatar_proxy/v4/letter/j/958977/32.png) [@juanpab2](https://www.phphelp.com/u/juanpab2)\
**Post date:** [April 4, 2008, 3:12am UTC](https://www.phphelp.com/t/login-script/11137/1 "2008-04-04T03:12:00Z")

</div>

I’ve found lots of login script all over the internet but I can’t get any of it to work. I have a MySQL. At first I thought it was just the code, now I think it is my connection options.  
First of all I type in my server which is [quotaless.com](http://quotaless.com).  
Then it ask for the user name which i will simulate as xxxxxx\_user1.  
then my password xxxxx. I know I have the password right.  
And I’m sure I have my database right as well. but what I’m wondering is if the servername would be the full url [http://www](http://www). and so on. I’ve tried this one other time for a comments installer and it said my access for my account was denied, but I can login just fine. And one other thing about it is that when I login with just xxxxxx\_user1 and once logged in it says xxxxxx\_user1@localhost does the @localhost matter at all. I when though the code and everything looks fine.  
Any help would be much appriciated.  
Thanks

---

<div class="post-metadata">

**Author:** ![Zyppora](https://www.phphelp.com/letter_avatar_proxy/v4/letter/z/76d3ee/32.png) [@Zyppora](https://www.phphelp.com/u/Zyppora)\
**Post date:** [April 4, 2008, 8:42am UTC](https://www.phphelp.com/t/login-script/11137/2 "2008-04-04T08:42:47Z")

</div>

Can we see the connection part of your code? Sounds like you just haven’t set up your user permissions yet.

---

<div class="post-metadata">

**Author:** ![juanpab2](https://www.phphelp.com/letter_avatar_proxy/v4/letter/j/958977/32.png) [@juanpab2](https://www.phphelp.com/u/juanpab2)\
**Post date:** [April 4, 2008, 8:57pm UTC](https://www.phphelp.com/t/login-script/11137/3 "2008-04-04T20:57:29Z")

</div>

Here’s the registration code that is suppose to be entered in to the database.

```auto
<!--p
//Start session
session_start();
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect("host","user_name","password");
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db("username_login");
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$fname = clean($_POST['fname']);
$lname = clean($_POST['lname']);
$login = clean($_POST['login']);
$password = clean($_POST['password']);
$cpassword = clean($_POST['cpassword']);
//Input Validations
if($fname == '') {
$errmsg_arr[] = 'First name missing';
$errflag = true;
}
if($lname == '') {
$errmsg_arr[] = 'Last name missing';
$errflag = true;
}
if($login == '') {
$errmsg_arr[] = 'Login ID missing';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'Password missing';
$errflag = true;
}
if($cpassword == '') {
$errmsg_arr[] = 'Confirm password missing';
$errflag = true;
}
if( strcmp($password, $cpassword) != 0 ) {
$errmsg_arr[] = 'Passwords do not match';
$errflag = true;
}
//Check for duplicate login ID
$qry = "SELECT count(*) AS c FROM members WHERE login='$login'";
$result = mysql_query($qry);
if($result) {
$result_array = mysql_fetch_assoc($result);
if($result_array['c'-->0) { $errmsg_arr[] = 'Login ID already in use'; $errflag = true; } @mysql_free_result($result); } else { die(&quot;Query failed&quot;); } //If there are input validations, redirect back to the registration form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header(&quot;location: register-form.php&quot;); exit(); } //Create INSERT query $qry = &quot;INSERT INTO members(firstname, lastname, login, passwd) VALUES('$fname','$lname','$login','&quot;.md5($_POST['password']).&quot;')&quot;; $result = mysql_query($qry); //Check whether the query was successful or not if($result) { header(&quot;location: register-success.php&quot;); exit(); }else { die(&quot;Query failed&quot;); } ?&gt;
```

for the privileges when i made my username, i just allowed all, if those are the privileges you were talking about.  
Thanks
