Jump to content

[SOLVED] can't connect to database


flash gordon

Recommended Posts

Can anybody see what is wrong with this script? The error message is:

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2) in /home/content/r/i/t/ritahunt/html/httpdocs/test/candleData.php on line 12
Could not connect

 

and the script I'm using is:

/*
* DATABASE INFO
*/
$username = "Phil01";
$password = "******";
$db       = "Phil01";
$table    = "candledata"; 

// Conect to the database.
mysql_connect("localhost", $username, $password) or die ("Could not connect to database");
mysql_select_db($database) or die ("Could not select database");

 

It works fine on my own host and locally. However, when I upload it to the GoDaddy server it doesn't work. I don't know enough php to understand what the problem is.

 

help?

Cheers

:)

Link to comment
Share on other sites

GoDaddy is a PoS.

 

But just login to your domain name's control panel, and click Databases. There you should see a list of databases along with what type they are, click the database name, it will show you the host and name.

 

For GoDaddy, host and username for mySQL connections are the same.

Link to comment
Share on other sites

Ok, you probably need to be logged into your GoDaddy account...

 

Go to 'My Account'.

 

In the far right side of the top nav bar is a question mark (?). Click it to go to the Knowledge Center (url ends up help.godaddy.com). In the search box, type in mysql server. Under result 21, for linux or windows shared hosting, is the directions for setting up and connecting to your mysql database. Note:

 

Once you have set up a database for your account' date=' you can click on the Pencil icon next to the name of your database to find your host name information.[/quote']

 

PhREEEk

Link to comment
Share on other sites

Thanks guys! I got it connecting now. That's awesome! Unforntualely I have a bunch of SQL errors now that I don't get anywhere else, but it is working. yea! You guys rock. Ever need some flash help come on over to actioscript.org!

 

If anyone see something that sticks out....let me know about this error.

/**
* Used for testing
*/

$_POST['position'] = '123,456';
$_POST['name'] = 'Julie';
$_POST['lit'] = 'true';



$ip = $_SERVER['REMOTE_ADDR'];

// if only position is posted
if( !isset($_POST['lit']) && !isset($_POST['name']) && isset($_POST['position']) )
{
// add data to 
$position = $_POST['position']; 
$sql = "INSERT INTO $table VALUES('', '$ip', '$position', '', '')";
mysql_query($sql) or die(mysql_error());
}

// if position and name is set, add name
else if( !isset($_POST['lit']) && isset($_POST['name']) && isset($_POST['position']) )
{
$position = $_POST['position']; 
$name = $_POST['name']; 

// find which row to update
$sql = "SELECT * FROM $table WHERE ip = '$ip' AND position = '$position'"; // <-- error here?
$result = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_array($result);
$id = $row['id'];

// update the row
$sql = "UPDATE $table SET name = '$name' WHERE id = '$id'";
mysql_query($sql) or die(mysql_error());
}

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE ip = '64.193.88.5' AND position = '123,456'' at line 1

Link to comment
Share on other sites

yea, i just didn't include the full code.

If you want everything here it is:

<?php
//Connect To Database
//$hostname='p50mysql55.secureserver.net';
$hostname='p41mysql103.secureserver.net';
$username='mycandle';
$password='******';
//$dbname='mycandle';
$dbname='Phil01';
$username='Phil01';
$usertable='your_tablename';
$yourfield = 'your_field';
$tale = "candledata";

mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);

/**
* Used for testing
*/

$_POST['position'] = '123,456';
$_POST['name'] = 'Julie';
$_POST['lit'] = 'true';



$ip = $_SERVER['REMOTE_ADDR'];

// if only position is posted
if( !isset($_POST['lit']) && !isset($_POST['name']) && isset($_POST['position']) )
{
// add data to 
$position = $_POST['position']; 
$sql = "INSERT INTO $table VALUES('', '$ip', '$position', '', '')";
mysql_query($sql) or die(mysql_error());
}

// if position and name is set, add name
else if( !isset($_POST['lit']) && isset($_POST['name']) && isset($_POST['position']) )
{
$position = $_POST['position']; 
$name = $_POST['name']; 

// find which row to update
$sql = "SELECT * FROM $table WHERE `ip` = '$ip' AND `position` = '$position'";
$result = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_array($result);
$id = $row['id'];

// update the row
$sql = "UPDATE $table SET name = '$name' WHERE id = '$id'";
mysql_query($sql) or die(mysql_error());
}


// if all data is set
else if (isset($_POST['lit']) && isset($_POST['name']) && isset($_POST['position']) )
{
$position = $_POST['position']; 
$lit = ($_POST['lit'] == "true") ? 1 : 0; 

// find which row to update
$sql = "SELECT * FROM $table WHERE `ip` = '$ip' AND `position` = '$position'";
$result = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_array($result);
$id = $row['id'];

	// update the row
$sql = "UPDATE $table SET lit = '$lit' WHERE id = '$id'";
mysql_query($sql) or die(mysql_error());
}

mysql_close();
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.