Johns3n Posted January 14, 2010 Share Posted January 14, 2010 Hello PHPFreaks! I am nearly done with my project which is a small Blog CMS, however I have run into a couple of problems that I have posted to this forum, in the hopes that you users might be able to assist me with! This might seem like a complete newbie question, but interestingly enough that is exactly what I am ^^ However regardless of the difficulty of the problem, it is a problem that has been giving me a headache for the past few hours, so I was hoping that there were some PHPfreaks what might be of assistance and seeing where my problem(s) lie, as I am afraid I have stared myself blind to the problem. At first I thought it was possible to just use a MySQL query to call some values into some metatags! It might be that simple and I just made a simple mistake, but really hoping you can help me! I supplied the code in question below ?php include("config.php"); ?> <?php $params = mysql_query("SELECT * FROM ". db_prefix ."parameters"); while($site_params = mysql_fetch_assoc($params)) { echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"; echo "<html xmlns='http://www.w3.org/1999/xhtml'>"; echo "<head>"; echo "<meta name='Keywords' content='" . $site_params['site_keywords'] . "' />"; echo "<meta name='Description' content='" . $site_params['site_description'] . "' />"; echo "<title>" . $site_params['site_title'] . "</title>"; } ?> <meta name="Robots" content="ALL" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="alternate" title="RSS" href="*********/rss.php" type="application/rss+xml" /> <link href="default.css" rel="stylesheet" type="text/css" media="all" /> </head> <body> The page it self, renders perfectly, however everything in the echo tags are simply left out of the code. In advance thanks! (P.S I am rookie at both PHP and SQL, so when if you need to explain something to me, do not take it I know things for granted xD) Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/ Share on other sites More sharing options...
Buddski Posted January 14, 2010 Share Posted January 14, 2010 $params = mysql_query("SELECT * FROM ". db_prefix ."parameters") or trigger_error(mysql_error()); It looks to me like your query is failing for some reason this will tell you why.. And after looking at your other post you are missing a $ on db_prefix Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994841 Share on other sites More sharing options...
Johns3n Posted January 14, 2010 Author Share Posted January 14, 2010 $params = mysql_query("SELECT * FROM ". db_prefix ."parameters") or trigger_error(mysql_error()); It looks to me like your query is failing for some reason this will tell you why.. And after looking at your other post you are missing a $ on db_prefix I did try running my SQL statement through the DB earliere and it did return the values I needed then But I did try to do as you said, however it did nothing Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994843 Share on other sites More sharing options...
Buddski Posted January 14, 2010 Share Posted January 14, 2010 ensure you have error_reporting turned on error_reporting(E_ALL); ini_set('display_errors',1); Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994845 Share on other sites More sharing options...
Rizla Posted January 14, 2010 Share Posted January 14, 2010 I found another typo: ?php include("config.php"); ?> should be <?php include("config.php"); ?> why do you open and close php twice? one time will do <?php include("config.php"); $params = mysql_query("SELECT * FROM ". db_prefix ."parameters"); while($site_params = mysql_fetch_assoc($params)){} ?> and do u use mysql_fecht_assoc, try mysql_fetch_array btw, can u show the config file? Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994847 Share on other sites More sharing options...
Buddski Posted January 14, 2010 Share Posted January 14, 2010 if (mysql_num_rows($params) > 0) { while($site_params = mysql_fetch_assoc($params)) { echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"; echo "<html xmlns='http://www.w3.org/1999/xhtml'>"; echo "<head>"; echo "<meta name='Keywords' content='" . $site_params['site_keywords'] . "' />"; echo "<meta name='Description' content='" . $site_params['site_description'] . "' />"; echo "<title>" . $site_params['site_title'] . "</title>"; } } else { trigger_error('No Data found'); } Come to think of it.. you probably dont need a loop as I am presuming you only have 1 row in the parameters table otherwise you will have more than 1 doctype, title etc.. so you can just do if (mysql_num_rows($params) > 0) { $site_params = mysql_fetch_assoc($params); //echo your stuff here } Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994850 Share on other sites More sharing options...
Johns3n Posted January 14, 2010 Author Share Posted January 14, 2010 ensure you have error_reporting turned on error_reporting(E_ALL); ini_set('display_errors',1); For some strange reason error reporting is not working for me at all! Tried turning it on multiple times I found another typo: ?php include("config.php"); ?> should be <?php include("config.php"); ?> why do you open and close php twice? one time will do <?php include("config.php"); $params = mysql_query("SELECT * FROM ". db_prefix ."parameters"); while($site_params = mysql_fetch_assoc($params)){} ?> and do u use mysql_fecht_assoc, try mysql_fetch_array btw, can u show the config file? It is indeed a typo and the missing "<" is present in the file im editting, so the problem isn't there But thanks for pointing it out As for the config.php: <?php // Connection string $con = mysql_connect(localhost,*******,********); // If no connection is made generate a error warning if (!$con) { die('Ohh no! Could not connect: ' . mysql_error()); } // Selects the Database mysql_select_db(*******, $con); $db_prefix = 'lork_'; ?> However I 99% sure the problem isn't in the config.php file either since it has worked perfectly on other pages in the project to call mySQL queries Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994851 Share on other sites More sharing options...
Johns3n Posted January 14, 2010 Author Share Posted January 14, 2010 Come to think of it.. you probably dont need a loop as I am presuming you only have 1 row in the parameters table otherwise you will have more than 1 doctype, title etc.. so you can just do if (mysql_num_rows($params) > 0) { $site_params = mysql_fetch_assoc($params); //echo your stuff here } Right you are! There is only one row in the parameters table! I inserted the code you suggested, however with the same result as the with the "while" loop, it renders the page, but the everything in the echo's are still missing in the source code. Sorry for being this pain! Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994855 Share on other sites More sharing options...
Buddski Posted January 14, 2010 Share Posted January 14, 2010 if (mysql_num_rows($params) > 0) { $site_params = mysql_fetch_assoc($params); //echo your stuff here } else { die('Something is Missing wrong!'); } try that.. it will tell you if your query is working as it should.. Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994856 Share on other sites More sharing options...
Rizla Posted January 14, 2010 Share Posted January 14, 2010 as another person already mensioned you're missing a $ on db_prefix is this the case in your file or just in this post? ==> $params = mysql_query("SELECT * FROM ". db_prefix ."parameters"); should be ==> $params = mysql_query("SELECT * FROM ". $db_prefix ."parameters"); Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994859 Share on other sites More sharing options...
Johns3n Posted January 14, 2010 Author Share Posted January 14, 2010 as another person already mensioned you're missing a $ on db_prefix is this the case in your file or just in this post? ==> $params = mysql_query("SELECT * FROM ". db_prefix ."parameters"); should be ==> $params = mysql_query("SELECT * FROM ". $db_prefix ."parameters"); Damn I feel like moron at the moment! >< This was indeed to problem that made it crash! Thank you! I'm sorry Buddski, I completely missed you pointing this out to me in your post! Sorry! Somebody should seriously revoke my pass to code after this! ^^ This is now solved! Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994860 Share on other sites More sharing options...
Rizla Posted January 14, 2010 Share Posted January 14, 2010 Hehe, everyone can overlook something. I had similare problems several times before. But you learn from these mistakes. I have one tip for you: save and test after every change you make to your files this way you know where and when you're problem started. Greetings Rizla Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994866 Share on other sites More sharing options...
ignace Posted January 14, 2010 Share Posted January 14, 2010 Strange that everyone missed this: while($site_params = mysql_fetch_assoc($params)) { echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"; echo "<html xmlns='http://www.w3.org/1999/xhtml'>"; echo "<head>"; echo "<meta name='Keywords' content='" . $site_params['site_keywords'] . "' />"; echo "<meta name='Description' content='" . $site_params['site_description'] . "' />"; echo "<title>" . $site_params['site_title'] . "</title>"; } Which should be: <!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'> <head> <?php $site_params = mysql_fetch_assoc($params, MYSQL_ASSOC); ?> <meta name='Keywords' content='<?php print $site_params['site_keywords']; ?>' /> <meta name='Description' content='<?php print $site_params['site_description']; ?>' /> <title><?php print $site_params['site_title']; ?></title> Edit: oeps apparently Buddski did My bad! Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994942 Share on other sites More sharing options...
Rizla Posted January 14, 2010 Share Posted January 14, 2010 @ignace: lol thats so true Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994944 Share on other sites More sharing options...
Buddski Posted January 14, 2010 Share Posted January 14, 2010 And ignace: this $site_params = mysql_fetch_assoc($params, MYSQL_ASSOC); is wrong i think your thinking of $site_params = mysql_fetch_array($params, MYSQL_ASSOC); Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994948 Share on other sites More sharing options...
Rizla Posted January 14, 2010 Share Posted January 14, 2010 And ignace: this $site_params = mysql_fetch_assoc($params, MYSQL_ASSOC); is wrong i think your thinking of $site_params = mysql_fetch_array($params, MYSQL_ASSOC); Said the same thing but, whats the fetch_assoc for? Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994957 Share on other sites More sharing options...
Buddski Posted January 14, 2010 Share Posted January 14, 2010 Rizla: was that a question? im a little confused.. Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994964 Share on other sites More sharing options...
Rizla Posted January 14, 2010 Share Posted January 14, 2010 Sorry for confusing you. yes it's a question. What is "mysql_fetch_assoc" and when do u chose to use this instead of "mysql_fecht_array"? Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994971 Share on other sites More sharing options...
Buddski Posted January 14, 2010 Share Posted January 14, 2010 mysql_fetch_assoc is exactly the same as mysql_fetch_array with the MYSQL_ASSOC const. as mysql_fetch_row is the same as mysql_fetch_array with the MYSQL_NUM const. and mysql_fetch_array with MYSQL_BOTH returns both NUM and ASSOC arrays.. Its been discussed here a few times. Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994973 Share on other sites More sharing options...
ignace Posted January 14, 2010 Share Posted January 14, 2010 Yeah I'm so used of people using mysql_fetch_array() without the second parameter I'm now just writing it out of habit Quote Link to comment https://forums.phpfreaks.com/topic/188447-problem-with-calling-mysql-queries-into-meta-tags/#findComment-994980 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.