/    Sign up×
Community /Pin to ProfileBookmark

mysql_connect() error, can’t connect through socket

Does anyone know what this error is about?

[B]script[/B]
<?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)

?>

[B]error[/B]
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)

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 12.2007 — Are you connecting to "localhost" or to an IP address/hostname? If "localhost", try using the IP address 127.0.0.1 instead.
Copy linkTweet thisAlerts:
@DREWauthorJul 12.2007 — 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


[B]error adding new person?uplicate entry '0' for key 1[/B]


[B]code[/B]

$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>';
}
?>
Copy linkTweet thisAlerts:
@pcthugJul 12.2007 — Can we have a look at your members table?
Copy linkTweet thisAlerts:
@cluettrJul 12.2007 — 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.
Copy linkTweet thisAlerts:
@NogDogJul 12.2007 — Looks like you probably should alter the table definition to make the id field AUTO_INCREMENT.
Copy linkTweet thisAlerts:
@pcthugJul 12.2007 — And there is no need for your id field to have a default value of [FONT=Courier New]0[/FONT]
Copy linkTweet thisAlerts:
@DREWauthorJul 12.2007 — Thanks guys, I dropped the table and recreated with primary key using auto increment and voila!

champions!

Cheers,

Andrew
×

Success!

Help @DREW spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...