Jump to content

[SOLVED] Quick Questions PHP


Ell20

Recommended Posts

I have tried to query the database in the normal way and for some reason its not working:

 

<?php 
header("Content-type: text/css");
require_once ('mysql_connect.php');
include_once ('includes/functions.php');
$id = $_SESSION['club_id'];

$query = "SELECT * FROM club WHERE club_id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);

$bgcolour = $row['bgcolour'];
$textcolour = $row['textcolour'];
?>

body {
color: <?=$textcolour?>;
background-color: <?=$bgcolour?>;
}

 

Can you see anything wrong with this?

 

Thanks

Should be:

<?php 
header("Content-type: text/css");
require_once ('mysql_connect.php');
include_once ('includes/functions.php');
$id = $_SESSION['club_id'];

$query = "SELECT * FROM club WHERE club_id = '$id'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);

$bgcolour = $row['bgcolour'];
$textcolour = $row['textcolour'];
?>
body {
color: <?php echo $textcolour; ?>;
background-color: <?php echo $bgcolour; ?>;
}

Well, lets firstly make sure your query works before trying to use its result. This is always good practice.

 

<?php

session_start();

header("Content-type: text/css");
require_once ('mysql_connect.php');
include_once ('includes/functions.php');

$id = $_SESSION['club_id'];

$query = "SELECT * FROM club WHERE club_id = '$id' LIMIT 1";
if ($result = mysql_query($query)) {
  if (mysql_num_rows($result)) {
    $row = mysql_fetch_assoc($result);
    $bgcolour = $row['bgcolour'];
    $textcolour = $row['textcolour'];
  } else {
    echo "No record found";
  }
} else {
  echo Query failed " . mysql_error();
}
?>
body {
  color: <?php echo $textcolour; ?>;
  background-color: <?php echo $bgcolour; ?>;
}

 

I also noticed you where missing a call to session_start().

That dosent work either, no message displayed either.

 

Is the possible reason for this that on the php page header.html is called, header.html then calls the CSS?

 

The reason there is no session_start() is because the header.html includes this, which is included on every page.

 

Thanks

The reason there is no session_start() is because the header.html includes this, which is included on every page.

 

Is your server configured to handle html as php? By the way... what file extension is on the code you have posted? *.php ?

 

I have no idea, before I attempted to make the changes to the CSS it was working fine.

 

The code I have posted is newcss.php.

 

Thanks

thorpe missed a quote.

 

<?php

session_start();

header("Content-type: text/css");
require_once ('mysql_connect.php');
include_once ('includes/functions.php');

$id = $_SESSION['club_id'];

$query = "SELECT * FROM club WHERE club_id = '$id' LIMIT 1";
if ($result = mysql_query($query)) {
  if (mysql_num_rows($result)) {
    $row = mysql_fetch_assoc($result);
    $bgcolour = $row['bgcolour'];
    $textcolour = $row['textcolour'];
  } else {
    echo "No record found";
  }
} else {
  echo "Query failed " . mysql_error();
}
?>
body {
  color: <?php echo $textcolour; ?>;
  background-color: <?php echo $bgcolour; ?>;
}

Thanks Ken, but still no luck.

 

To answer a previous question about the php being used in html.

 

I think it must work because when I set say $bgcolour = '#fffff';

 

Then use echo in the CSS it works, its just when I attempt to get a value from the database that its just going white with no CSS at all.

 

Thanks

If by not work, do you mean the variables are empty? Because I think that's the case. Can you page source the page and find that part of the CSS and copy and paste it here? In firefox, you just press Ctrl+U, in IE, you go to Edit and Page Source. (I think, not sure since I don't use IE)

If by not work, do you mean the variables are empty? Because I think that's the case. Can you page source the page and find that part of the CSS and copy and paste it here? In firefox, you just press Ctrl+U, in IE, you go to Edit and Page Source. (I think, not sure since I don't use IE)

 

I dont see how the variables can be empty as I have manually placed them in the database.

 

CSS dosent show up in page source, all I can see is this:

<link media="screen" href="/includes/newcss.php" rel="stylesheet" type="text/css" />

 

Thanks

I went to: /includes/newcss.php

 

And I found this:

 

<br />

<b>Warning</b>:  require_once(mysql_connect.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream: No such file or directory in <b>/home/mysport/public_html/includes/newcss.php</b> on line <b>3</b><br />

<br />

<b>Fatal error</b>:  require_once() [<a href='function.require'>function.require</a>]: Failed opening required 'mysql_connect.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in <b>/home/mysport/public_html/includes/newcss.php</b> on line <b>3</b><br />

Archived

This topic is now archived and is closed to further replies.

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