...

View Full Version : weird php mysql error



docock
06-17-2010, 10:31 AM
I'm trying to execute the script below, but I'm getting this as result:

[phpBB Debug] PHP Notice: in file /mdwphp/add_gmember.php on line 47: mysql_query(): supplied argument is not a valid MySQL-Link resource
Er is een fout opgetreden: INSERT INTO 'hello' VALUES ('gpfsjaak','1', 'July 17 2010','pictures','test.jpg'); :Access denied for user 'a3718717_members'@'192.168.0.3' to database 'hello'

I'm using a phpbb script earlier in the script, but that has nothing to do with the error. The phpdebug says it's not a valid Mysql link resource at $result = mysql_query($string,$db_selected); Though I checked everything and all database/host settings are filled in correctly. Perhaps there is an error in the way I try to connect?




$string = "INSERT INTO 'hello' VALUES ('$gebruiker','1', '$today_plus_1_month','pictures','test.jpg');";



$con = mysql_connect("mysql3.***************","a3718717_members",$wachtwoord);
$db_selected = mysql_select_db('hello', $con);

if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$result = mysql_query($string,$db_selected);

if (!$result) {echo "Er is een fout opgetreden: $string :". mysql_error();}else{echo "1 record added";}
mysql_close($con);

}
?>

Zoic
06-17-2010, 11:00 AM
The access denied error means that your connection information is either wrong or your not allowed to connect to the server from the IP address your running the script from.

Are you trying to connect to a remote database on a different server than the script is running? If so, have you white listed the IP address of the site/server/computer your script is on?

Also, some times you don't need to specify the connection in your mysql functions (such as mysql_select_db and mysql_query). Try it without that 2nd (optional) parameter that specifies the connection and see if you still get an error.

abduraooft
06-17-2010, 11:44 AM
It'd give a much more descriptive error if you put it like

$con = mysql_connect("mysql3.***************","a3718717_members",$wachtwoord) or die( mysql_error());

Zoic
06-17-2010, 11:52 AM
It'd give a much more descriptive error if you put it like

$con = mysql_connect("mysql3.***************","a3718717_members",$wachtwoord) or die( mysql_error());


^ first step to figuring out any problems with mysql queries. It may be tedious to add those in after every, single, mysql, function, but in the end its worth the time.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum