Jump to content

[SOLVED] help with PHP/MySQL connection error please!


whit555

Recommended Posts

Hi everybody! I'm hoping to get a little help with an error I'm getting. Here it is:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /path/index.php on line 20

Error executing query SELECT Content.ContentID, Content.SectionName, Content.Title, Content.Body, Content.PictureID, Pictures.PictureName FROM Pictures INNER JOIN Content ON Pictures.PictureID = Content.PictureID WHERE (((Content.ContentID)=9));

 

NOw, I've seen a couple other posts related to this error and checked out some articles (http://forge.mysql.com/wiki/Error2003-CantConnectToMySQLServer) but I guess I'm too much of a beginner to figure it out on my own.

 

I should mention that all of this code was working fine until I changed hosts which makes me think that its to do with settings somewhere. I have taken a look at php.ini but would need a little guidance on what to include in that file.

 

Now, the thing is that the database is being successfully contacted because it displays the site's main page but will not display anything else but that. I hope I'm making sense here, I'll include the code just in case I'm making a mistake there:

 

<?php 

ob_start(); 
session_start(); 
echo "<?xml version='1.0' encoding='iso-8859-1'?>\r\n"; 
?> 

<?php 
//declare initial value for the page title 
$strTitle = "Upper Canada Equestrian Association | "; 
$strPart = ""; 
$strPage = ""; 

//catch the value of this variable to switch title and pages 
if(isset($HTTP_GET_VARS["Part"])) 
{ 
$strPart = $HTTP_GET_VARS["Part"]; 
} 
else 
{ 
$strPart = "Home"; 
} 

//change the page title and the main content below in the file to the appropriate part 
switch($strPart) 
{ 
case "AboutUs": 
$strTitle .= "About the UCEA"; 
break; 

case "Membership": 
$strTitle .= "Membership Information"; 
break; 

case "Events": 
$strTitle .= "Club Events"; 
break; 

case "Newsletter": 
$strTitle .= "Makin' Trails"; 
break; 

case "Pictures": 
$strTitle .= "Member and Event Pictures"; 
break; 

case "ContactUs": 
$strTitle .= "Contact Us"; 
break; 

case "Links": 
$strTitle .= "Links"; 
break; 

case "Login": 
$strTitle .= "Login"; 
break; 

case "Logout": 
$strTitle .= "Logout"; 
break; 

default: 
$strTitle .="Official Website"; 
break; 
} 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">; 

<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en"> 
<head> 
<title><?= $strTitle ?></title> 
<link rel="stylesheet" href="css/adminCSS.css" /> 


</head> 

<body leftmargin="1" marginheight="0" marginwidth="1" topmargin="0"> 



<?php 
/*	set connection variables for all pages being included into index.php that need 
to connect to the database*/ 
// old conection string 
$mysql_server = "hostname"; 
$db_name = "dbname"; 
$mysql_userid = "userid"; 
$mysql_password = "password"; 
//	connect to MySQL using username and password 
$link_id = mysql_connect($mysql_server,$mysql_userid,$mysql_password); 
//	select the "thecollected" database to work on 
if(!mysql_select_db($db_name)) die("Error selecting $db_name database"); 

/*	
finished setting up database connections 
*/ 

//retrieve the about us information from the content table 
$sql = "SELECT Content.SectionName, Content.Title, Content.PictureID, Pictures.PictureName, Content.PictureAlt 
FROM Pictures INNER JOIN Content ON Pictures.PictureID = Content.PictureID WHERE Title = '$strPart';"; 

if(!($mysql_rs = mysql_query($sql, $link_id)))	die("Error executing query $sql"); 

while($row = mysql_fetch_row($mysql_rs)) 
{ 
//create local variables from database fields 
$result = mysql_db_query($db_name,$sql,$link_id); 
$sectionname = $row[0]; 
$title = $row[1]; 
$picturename = $row[3]; 
$picturealt = $row[4]; 
$pictureid = $row[2]; 
} 
?> 

<?php 
include("Includes/header.php"); 
?> 
<!-- start content --> 

</tr> 
<tr> 
<td colspan=3 width=87 height=463 leftmargin="2"> 
<!-- main content part of the page, this is where the action happens --> 

<?php 
//switch the content depending on the page value from above 
switch($strPart) 
{ 
case "AboutUs": 
include("AboutUs/index.php"); 
break; 

case "Membership": 
include("Membership/index.php"); 
break; 

case "Events": 
include("Events/index.php"); 
break; 

case "Newsletter": 
include("Newsletter/index.php"); 
break; 

case "Pictures": 
include("Pictures/index.php"); 
break; 

case "ContactUs": 
include("ContactUs/index.php"); 
break; 

case "Links": 
include("Links/index.php"); 
break; 

case "Login": 
include("Login/index.php"); 
break; 

case "Logout": 
include("Logout/index.php"); 
break; 

default: 
include("Home/index.php"); 
break; 
} 
?> 
</td> 
</tr> 
<!-- end content --> 

</body> 
</html> 

 

Of course, I've taken out all the correct connection stuff above. So, the database will happily display Home/index.php but when the others are clicked on it won't change to those entries from the database and when I try to force it by typing in the url directly for the page (ex. "url.com/Login/index.php" rather than "url.com/index.php?Part=Login") I get the above error.

So, whats up here? Is there something I need to change in php.ini in order to keep the connection open?

 

Thanks very much for any guidance!!

 

 

Link to comment
Share on other sites

Thanks for the suggestion.  I added mysql_error to see if it made a difference but it hasn't.  The database connects fine the first time and it appears that after that it loses the connection.  I'm really not sure what's going on...

Link to comment
Share on other sites

Perhaps its not a connection error after all.  Can anyone see a reason (in my code) why it would only display a certain entry in the database?  In this case, the default page:

default:

include("Home/index.php");

break;

No matter what I do it will only display this page.

Now, I imported the database from a backup made by CocoaMySQL (admin app for Mac) to godaddy's built-in MySQL admin.  Could that have changed any settings that would cause this?

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.