Jump to content

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
https://forums.phpfreaks.com/topic/77406-solved-cant-connect-to-database/
Share on other sites

For you server, you may have to put something other than "localhost". If I remember right, when I used GoDaddy I had to put the actual server. If you browse through the help files you will find what your supposed to use.

Thanks Daukan, but that's just a mistake on my part. I double checked it, and I still get that error.

 

@pocobueno1388, yea that was my though too so I called godaddy but the told me they offer now support for there hosting packages. I couldn't find what I was supposed to use....

I tried calling them and they said they offer no support for their hosting packages. They wont tell me what that first param should be and I don't know how to find out. Additionally, I don't even know if that IS the problem or not as my php experience is rather limited. I don't know what to do.

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.

Oh, I agree. I'm was just doing some flash work and was forced to use GoDaddy. Is this what you mean:

 

MySQL Database

InformationStatus:SetupHost

Name:p41mysql103.secureserver.netDatabase

Name:Phil01

Database Version:4.1

Description:Not SetUser

Name:Phil01

 

Does that tell you anything?

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

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

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();
?>

Wow....thanks guys! In the midst of making soo many databases and trying different stuff, I got sloppy.

 

Sorry I can't help out around here any, but as you can see my PHP is rather bad. If you every need some flash help, come on over to AS[org]

 

You guys rock!

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.