Click to See Complete Forum and Search --> : mysql_connect() error, can't connect through socket


DREW
07-11-2007, 06:37 PM
Does anyone know what this error is about?

script
<?php

if(isset($_POST["adduser"]))

$host = ".....";
$dbname = ".....";
$username = ".....";
$password = ".....";
$connection = mysql_connect($host, $username, $password);

if (!$connection)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname, $connection);
$sql="INSERT INTO members (username, password)
VALUES('$_POST[myusername]','$_POST[mypassword]')";
if (!mysql_query($sql,$connection))
{
die('Error: ' . mysql_error());
}
//echo "added";
echo"Username: $myusername and Password $mypassword added";
mysql_close($connection)

?>



error
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /clientdata/clients/e/m/eminenceproductions.com.au/www/eminence/adduser.php on line 30
Could not connect: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

NogDog
07-11-2007, 08:34 PM
Are you connecting to "localhost" or to an IP address/hostname? If "localhost", try using the IP address 127.0.0.1 instead.

DREW
07-11-2007, 09:17 PM
thanks I tried that but no change.

I've played around with the code a bit change some things and I got rid of that error but now i have this error


error adding new person:Duplicate entry '0' for key 1


code

$connection = mysql_connect($host, $username, $password);

if (!$connection)
{
die('Could not connect: ' . mysql_error());
}
if (!@mysql_select_db($dbname)){
exit ('<p>unable to locate the database</p>');
}
$name= $_POST['myusername'];
$password= $_POST['mypassword'];
$sql="INSERT INTO members SET username ='$name', password ='$password'";
if (@mysql_query($sql)){
echo'<p>Username: $myusername and Password $mypassword added</p>';
}
else{
echo'<p>error adding new user:' . mysql_error() . '</p>';
}
?>

pcthug
07-11-2007, 10:02 PM
Can we have a look at your members table?

cluettr
07-11-2007, 10:49 PM
Check your mysql log file it should have more detailed information on what the error means. Post that back here and we'll be able to help.

DREW
07-11-2007, 11:18 PM
http://www.andrewdowd.net/membersTable.gif

NogDog
07-11-2007, 11:22 PM
Looks like you probably should alter the table definition to make the `id` field AUTO_INCREMENT.

pcthug
07-11-2007, 11:38 PM
And there is no need for your id field to have a default value of 0

DREW
07-12-2007, 12:15 AM
Thanks guys, I dropped the table and recreated with primary key using auto increment and voila!

champions!

Cheers,
Andrew