genista Posted May 14, 2006 Share Posted May 14, 2006 Hi guys,I have created a login page and am having problems with the connection to the database. Under $myhost I have entered the IP address for the MYSQL databse I have, however when I run the login script I get the following error:[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/fhlinux245/h/blah.cocom/user/htdocs/join_form2.php on line 117Warning: mysql_select_db(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/fhlinux245/h/blah.com/user/htdocs/join_form2.php on line 125Warning: mysql_select_db(): A link to the server could not be established in /home/fhlinux218/h/blah.com/user/htdocs/join_form2.php on line 125[!--colorc--][/span][!--/colorc--]Should I be entering something more specific for the $myhost or is this error something completly different. incidentally on line 117 the code reads:[b]$mysql = mysql_connect($myhost, $myuser, $mypass);[/b]if(!mysql){$error = "Cannot connect to the database";return($error);}Thanks Genista Quote Link to comment Share on other sites More sharing options...
_will Posted May 14, 2006 Share Posted May 14, 2006 Is your MySQL server running? Also, in your code, change the if statement to [code]if (!$mysql) { //...[/code] Quote Link to comment Share on other sites More sharing options...
genista Posted May 14, 2006 Author Share Posted May 14, 2006 Excuse me, but how do I check its running?G[!--quoteo(post=373801:date=May 14 2006, 12:57 PM:name=_will)--][div class=\'quotetop\']QUOTE(_will @ May 14 2006, 12:57 PM) [snapback]373801[/snapback][/div][div class=\'quotemain\'][!--quotec--]Is your MySQL server running? Also, in your code, change the if statement to [code]if (!$mysql) { //...[/code][/quote] Quote Link to comment Share on other sites More sharing options...
.josh Posted May 14, 2006 Share Posted May 14, 2006 try changing $host to 'localhost' $host = 'localhost'; Quote Link to comment Share on other sites More sharing options...
genista Posted May 14, 2006 Author Share Posted May 14, 2006 Just tried it - got the same error.I can use phpmyadmin to insert records into the database, does this mean it is on?G[!--quoteo(post=373822:date=May 14 2006, 02:49 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 14 2006, 02:49 PM) [snapback]373822[/snapback][/div][div class=\'quotemain\'][!--quotec--]try changing $host to 'localhost' $host = 'localhost';[/quote] Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 14, 2006 Share Posted May 14, 2006 If you can add data through phpmyadmin then your database is working. Normally, you would be able to use the server control panel to access MySQL and that's where you would find the 'connection string' that tells you the database name, your database username, etc. Also, that's where you would allow access/give permission for that username to the selected database. Try this - adjusted to suit - and see what happens.[code]<?php// define stuff$db_host = "localhost"; // most usually$db_pass = ''; // your database password$db_login = ''; // your database username$db_name = ''; // your database namemysql_connect($db_host, $db_login, $db_pass) or die ("Error: Unable to connect"); mysql_select_db($db_name) or die ("Error: Unable to open the database."); // ... more code ...[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.