FridayRain Posted October 10, 2007 Share Posted October 10, 2007 This is really irking me. I have poetry.php that allows users to select a title of a poem, which passes a variable through the URL and the poem is then displayed on the same page. I figured I should have the page title change to correspond with the poem selected. If no piece is selected, then no special title text is added to the page title. The code at the end of this post works if a poem is selected, but when a clean poetry.php is loaded, I get the following error: Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\Web\XXXX\db\closedb.php on line 2 <?php mysql_close($conn); ?> Dynamic page title code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <?php import_request_variables('G', 'url_'); if ((isset($_GET[piece])) && ($_GET[piece] != "")) { require("db/config.php"); require("db/opendb.php"); $query = "SELECT text, title, year FROM poems WHERE id=". mysql_escape_string($_GET[piece]); $result = mysql_query($query); $content = mysql_fetch_assoc($result); $title = "> $content[title]"; } else { $title = ""; } require("db/closedb.php"); ?> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title><?php echo "$title"; ?></title> <link rel="shortcut icon" href="favicon.ico" /> <link rel="stylesheet" type="text/css" href="css.css" media="Screen,Projection,TV" /> </head> The code is mostly identical to the code I use later in the page to display the piece selected, and it works fine. If no piece is selected, a message is displayed asking the user to select one. If a piece is selected, it displays. Since the code works when a piece is selected, I'm thinking there's an issue with the isset function. I'm not really sure, but I'm betting it's something stupid that I should know. Quote Link to comment https://forums.phpfreaks.com/topic/72694-solved-dynamic-page-titles/ Share on other sites More sharing options...
MadTechie Posted October 10, 2007 Share Posted October 10, 2007 change from $title = "> $content[title]"; to $title = $content['title']; Quote Link to comment https://forums.phpfreaks.com/topic/72694-solved-dynamic-page-titles/#findComment-366574 Share on other sites More sharing options...
MadTechie Posted October 10, 2007 Share Posted October 10, 2007 revised <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <?php import_request_variables('G', 'url_'); $ID = (int)$_GET['piece']; if ($ID > 0) { require("db/config.php"); require("db/opendb.php"); $query = "SELECT text, title, year FROM poems WHERE id=$ID"; $result = mysql_query($query); $content = mysql_fetch_assoc($result); $title = $content['title']; } else { $title = ""; } require("db/closedb.php"); ?> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title><?php echo $title; ?></title> <link rel="shortcut icon" href="favicon.ico" /> <link rel="stylesheet" type="text/css" href="css.css" media="Screen,Projection,TV" /> </head> Quote Link to comment https://forums.phpfreaks.com/topic/72694-solved-dynamic-page-titles/#findComment-366577 Share on other sites More sharing options...
Aureole Posted October 10, 2007 Share Posted October 10, 2007 Also instead of having a file for closing the db why not have a functions.php file that has all stuff like that in... <?php function dbConnect() { $dbhost = 'localhost'; $dbuser = ''; $dbpass = ''; $dbname = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass); $selectdb = mysql_select_db($dbname); if($conn) { if(!$selectdb) { return false; } else { return true; } } else { return false; } } function dbClose() { mysql_close($conn); } function freeResult($result) { mysql_free_result($result); } ?> I find it's an easier way of doing things. Quote Link to comment https://forums.phpfreaks.com/topic/72694-solved-dynamic-page-titles/#findComment-366580 Share on other sites More sharing options...
FridayRain Posted October 10, 2007 Author Share Posted October 10, 2007 MadTechie > I'm still getting the error. Aureole > I dunno. My way works fine for me. I'll save your code though. Quote Link to comment https://forums.phpfreaks.com/topic/72694-solved-dynamic-page-titles/#findComment-366589 Share on other sites More sharing options...
MadTechie Posted October 10, 2007 Share Posted October 10, 2007 can you post the opendb.php, (remove any passwords etc) Quote Link to comment https://forums.phpfreaks.com/topic/72694-solved-dynamic-page-titles/#findComment-366591 Share on other sites More sharing options...
FridayRain Posted October 10, 2007 Author Share Posted October 10, 2007 It's weird that the same config files work fine in every other MySQL query. <?php $dbhost = 'localhost'; $dbuser = 'XXXXX'; $dbpass = 'XXXXX'; $dbname = 'writing'; ?> <?php $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); mysql_select_db($dbname); ?> <?php mysql_close($conn); ?> Quote Link to comment https://forums.phpfreaks.com/topic/72694-solved-dynamic-page-titles/#findComment-366596 Share on other sites More sharing options...
Aureole Posted October 10, 2007 Share Posted October 10, 2007 Exactly how is the info from config.php getting to the opendb.php file? Try using constants. Quote Link to comment https://forums.phpfreaks.com/topic/72694-solved-dynamic-page-titles/#findComment-366599 Share on other sites More sharing options...
MadTechie Posted October 10, 2007 Share Posted October 10, 2007 I don't believe i missed that!!! your always attempting to close it.. just move it up, in the if block FIXED revised <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <?php import_request_variables('G', 'url_'); $ID = (int)$_GET['piece']; if ($ID > 0) { require("db/config.php"); require("db/opendb.php"); $query = "SELECT text, title, year FROM poems WHERE id=$ID"; $result = mysql_query($query); $content = mysql_fetch_assoc($result); $title = $content['title']; require("db/closedb.php"); } else { $title = ""; } ?> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title><?php echo $title; ?></title> <link rel="shortcut icon" href="favicon.ico" /> <link rel="stylesheet" type="text/css" href="css.css" media="Screen,Projection,TV" /> </head> Quote Link to comment https://forums.phpfreaks.com/topic/72694-solved-dynamic-page-titles/#findComment-366600 Share on other sites More sharing options...
FridayRain Posted October 10, 2007 Author Share Posted October 10, 2007 Ha, damn. I didn't notice either. I took pieces of an existing query and pasted the close command recklessly. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/72694-solved-dynamic-page-titles/#findComment-366603 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.