[RESOLVED] login error!!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mark103
Forum Newbie
Posts: 14
Joined: Sat Sep 20, 2008 9:41 am

[RESOLVED] login error!!!!

Post by mark103 »

Hi guys

Please can you help me, I am having trouble with my login page on my website. When I input the username and password, it said that it can't connect to local MySQL server through socket.




Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/www/mark107.awardspace.com/login/login-exec.php on line 15
Failed to connect to server: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)




why did i get this error??



Please help!!!!!!!!!!!



Thanks,
Mark
Last edited by mark103 on Thu Sep 25, 2008 12:57 pm, edited 1 time in total.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: login error!!!!

Post by califdon »

why did i get this error??
Impossible to say, without knowing much more than you have stated. The warning message tells you that the web server cannot connect to the database server, which could be caused by dozens of things. Do you have the correct connect string? Is the database server running? Are you using the correct port number? Is your user account authorized to use the database?

I would start by examining your connect string: is the host name correct? is the user name correct? is the password correct?

Can you access the database directly, using phpMyAdmin or something like that?
mark103
Forum Newbie
Posts: 14
Joined: Sat Sep 20, 2008 9:41 am

Re: login error!!!!

Post by mark103 »

Thanks for the reply, the code was working previously but it just new for me that i found on the website sample. I am using on free web hosting to test my login before i would then buying my own website. I am not using the server. Please can you confirm in which directory that mysql should be placed and should be called??



Something like this:
mark107.awardspace.com/login/login-exec.php



But I wasn't too sure, if you need to see my php code, here it is:

Code: Select all

<?php
    //Start session
    session_start();
    
    //Include database connection details
    require_once('config.php');
    
    //Array to store validation errors
    $errmsg_arr = array();
    
    //Validation error flag
    $errflag = false;
    
    //Connect to mysql server
        $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
        die('Failed to connect to server: ' . mysql_error());
    }
    
    //Select database
    $db = mysql_select_db(DB_DATABASE);
    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
    $login = clean($_POST['login']);
    $password = clean($_POST['password']);
    
    //Input Validations
    if($login == '') {
        $errmsg_arr[] = 'Login ID missing';
        $errflag = true;
    }
    if($password == '') {
        $errmsg_arr[] = 'Password missing';
        $errflag = true;
    }
    
    //If there are input validations, redirect back to the login form
    if($errflag) {
        $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
        session_write_close();
        header("location: login-form.php");
        exit();
    }
    
    //Create query
    $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'";
    $result=mysql_query($qry);
    
    //Check whether the query was successful or not
    if($result) {
        if(mysql_num_rows($result) == 1) {
            //Login Successful
            session_regenerate_id();
            $member = mysql_fetch_assoc($result);
            $_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
            $_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
            $_SESSION['SESS_LAST_NAME'] = $member['lastname'];
            session_write_close();
            header("location: member-index.php");
            exit();
        }else {
            //Login failed
            header("location: login-failed.php");
            exit();
        }
    }else {
        die("Query failed");
    }
?>

No i haven't put the username and password on my login php so shall i put my username and pass of my web hosting account on my login php??



Hope you can help to get my situation to resolve.


Thanks,
Mark
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: login error!!!!

Post by califdon »

mark103 wrote:Thanks for the reply, the code was working previously but it just new for me that i found on the website sample. I am using on free web hosting to test my login before i would then buying my own website. I am not using the server. Please can you confirm in which directory that mysql should be placed and should be called??

Something like this:
mark107.awardspace.com/login/login-exec.php
I think we have some terminology issues here. When you say "I am not using the server", I don't know what you mean. You have to use a web server to see anything, and you have to use a database server to use any database. So if you're not using both of those servers, you can't expect any script like that to work. Then you're using a sample script (from a different web site?), so it probably won't work without making changes. Certainly in the connect string, where your sample only shows "mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)", you must use the database server host name, database user name and database password. Assuming that you are asking where the PHP SCRIPT file (the one you showed us)--not the "mysql"-- goes, it is just like any other web page source document, it goes in the web server's document root or a subdirectory of that. Ordinarily, that's the only directory a user will have access to, anyway, on a hosted service, so you shouldn't have to worry about that, either.

In summary, you need to have a clear understanding of what it takes for a PHP script to access a MySQL database server. In addition to your hosting account login, MySQL requires a completely separate database username/password that you use in the connection string in your PHP code.
bungkusan
Forum Newbie
Posts: 20
Joined: Tue Sep 16, 2008 8:56 am

Re: login error!!!!

Post by bungkusan »

Code: Select all

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
are you sure that your connection strings are correct ?
Please check again :P
mark103
Forum Newbie
Posts: 14
Joined: Sat Sep 20, 2008 9:41 am

Re: login error!!!!

Post by mark103 »

Yes, I am sure that my connection string are correct. They are local on like for e.g: mysite.com/login/var/run/mysqld/mysql.sql



is that the correct place to get access to my connection string or they will have to be something like mysite.com/var/run/mysqld/mysql.sql??



I am not really sure sir....
bungkusan wrote:

Code: Select all

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
are you sure that your connection strings are correct ?
Please check again :P
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: login error!!!!

Post by califdon »

A typical connection string would look like this:

Code: Select all

mysql_connect("server123.somehost.com","george99","loosestool");
mark103
Forum Newbie
Posts: 14
Joined: Sat Sep 20, 2008 9:41 am

Re: login error!!!!

Post by mark103 »

Thanks for your help califdon, which software i can find out the username and password from mysql database??




Thanks,
Mark
califdon wrote:A typical connection string would look like this:

Code: Select all

mysql_connect("server123.somehost.com","george99","loosestool");
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: login error!!!!

Post by califdon »

No software can give you that information. If the mysql server is not running on your own machine (in which case, the host name would be "localhost"), you must ask the administrator of the host where the mysql server is located.
mark103
Forum Newbie
Posts: 14
Joined: Sat Sep 20, 2008 9:41 am

Re: login error!!!!

Post by mark103 »

Thanks for the help califdon, I have set up the database username and the password so i have input them on login-exec.php included the db host name, here it is the sample.

Code: Select all

$link = mysql_connect(db123.testsite.com, myname_data, mypassword);


Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'db123testsitecom' (1) in /home/www/myname.testsite.com/login/login-exec.php on line 15
Failed to connect to server: Unknown MySQL server host 'db123testsitecom' (1)




I am getting the error. What's wrong?? Have I missing something?? :(



Thanks,
Mark
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: login error!!!!

Post by califdon »

mark103 wrote:Thanks for the help califdon, I have set up the database username and the password so i have input them on login-exec.php included the db host name, here it is the sample.

Code: Select all

$link = mysql_connect(db123.testsite.com, myname_data, mypassword);
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'db123testsitecom' (1) in /home/www/myname.testsite.com/login/login-exec.php on line 15
Failed to connect to server: Unknown MySQL server host 'db123testsitecom' (1)


I am getting the error. What's wrong?? Have I missing something?? :(
Just read the error message. There is no MySQL server running at that URL. If you are trying to use the MySQL server at a commercial site that hosts your web page, you must contact them and determine what the correct URL is for the MySQL server for which you have permission.

If you want to use a database, the database server software MUST be running, you MUST have the correct host name or URL, you MUST have established a database account for that server, and you MUST use the user name and password that authorizes you to use the server.

Also, be sure that the 3 components in the connection string are real strings. That is, you must put quote marks around them.
mark103
Forum Newbie
Posts: 14
Joined: Sat Sep 20, 2008 9:41 am

Re: login error!!!!

Post by mark103 »

I have done it. Thanks for the help!!!! :D



Resolved!!!!
Post Reply