Jump to content

Recommended Posts

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)

$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

$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 :(

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?

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
}

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

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!

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..

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");

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!

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

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!

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.

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.