Page 1 of 1

Can't connect to MySQL server

Posted: Sun Feb 07, 2010 6:19 pm
by tristanhall
I am creating a PHP form that adds a record to a MySQL table. I have created the form and the PHP page that sends the data to the MySQL database. However whenever I submit the form I get the following error:
Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
The url for the form is http://www.lifegoesboom.com/open/index. ... =AddPerson. This is the code for the page that submits the data to the database:

Code: Select all

<?php
include "/open/mysql.php";
include "/open/functions/openconnection.php";
 
MYSQL_QUERY ("INSERT INTO `person` (`id`, `title`, `firstname`, `lastname`, `address1`, `address2`, `city`, `state`, `zipcode`, `homephone`, `workphone`, `mobilephone`, `emailaddress`, `spouse`, `child1`, `child2`, `child3`, `child4`, `child5`, `notes`, `amount`, `payments`) 
VALUES
('$_POST[title]','$_POST[firstname]','$_POST[lastname]','$_POST[address1]','$_POST[address2]','$_POST[city]','$_POST[state]','$_POST[zipcode]','$_POST[hoemphone]','$_POST[workphone]','$_POST[mobilephone]','$_POST[emailaddress]','$_POST[spouse]','$_POST[child1]','$_POST[child2]','$_POST[child3]','$_POST[child4]','$_POST[child5]','$_POST[notes]','$_POST[amount]','$_POST[payments]')");
 
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";
 
include ('/open/functions/closeconnection.php');
?>
I am a newbie to PHP but I will do my best to understand any help provided. Any and all help is greatly appreciated.
Thank you!
-Tristan

Re: Can't connect to MySQL server

Posted: Sun Feb 07, 2010 11:40 pm
by rahulzatakia
Hi,
You don't have problem in this file. You have problem in which you have code for connecting database. So check out the file and please check all the paths you have given are correct. If still you have problem then just give the code of connection file.

Re: Can't connect to MySQL server

Posted: Mon Feb 08, 2010 6:57 pm
by tristanhall
I followed the instructions that my web host provided and I modded a few variables and this is what I got. The problem is still ocurring.

Code: Select all

<?php
MYSQL_CONNECT($server, $user, $password) or die ( "<H3>Server unreachable</H3>");
          MYSQL_SELECT_DB($database) or die ( "<H3>Database non existent</H3>");
?>

Re: Can't connect to MySQL server

Posted: Mon Feb 08, 2010 9:16 pm
by tabutcher
hi,
I think you need to assign the function to a variable for example:

Code: Select all

 
resourceId = mysql_connect(server, username, password);
 
and when you are selecting a database the parameters to pass are the database name and the resource returned from the above connection function.

Code: Select all

 
mysql_select_db(databaseName, resourceId);
 
hope this leads you in the right direction.

Re: Can't connect to MySQL server

Posted: Mon Feb 08, 2010 9:27 pm
by tristanhall
I'm still having the same error message. I'm not sure if I did what you said correctly though. Here's what I put together:

Code: Select all

<?php
$con = MYSQL_CONNECT($server, $user, $password);
MYSQL_CONNECT($server, $user, $password) or die ( "<H3>Server unreachable</H3>");
          MYSQL_SELECT_DB($database,$con) or die ( "<H3>Database non existent</H3>");
?>

Re: Can't connect to MySQL server

Posted: Tue Feb 09, 2010 1:06 am
by rahulzatakia
Hi tristanhall, please use the following code,

<?php
$con = MYSQL_CONNECT($server, $user, $password);
MYSQL_SELECT_DB($database_name,$con) or die ( "<H3>Database non existent</H3>");
?>

Re: Can't connect to MySQL server

Posted: Tue Feb 09, 2010 10:14 pm
by tristanhall
Thank you for all the help everyone! I have decided to use Dreamweaver and reverse engineer its code.

Re: Can't connect to MySQL server

Posted: Wed Feb 10, 2010 1:33 am
by klevis miho
Do the $server, $user and $password variables have a value?
Also try to lowercase the functions.

Re: Can't connect to MySQL server

Posted: Wed Feb 10, 2010 2:03 am
by timon_sun
I think you should check out your firewall configuration, or you also could check your file and folder privilege on linux.

Good Luck!

Re: Can't connect to MySQL server

Posted: Thu Feb 11, 2010 12:56 am
by rahulzatakia
Hi klevis miho,
$server, $user, $password has the values...

$server = hostname
$user = database user name
$password = password of the database

Re: Can't connect to MySQL server

Posted: Thu Feb 11, 2010 1:38 am
by klevis miho
try to lowercase the function names