PHP / CSS incompatibility?

Thread Solved

Join Date: May 2008
Posts: 27
Reputation: xylude is an unknown quantity at this point 
Solved Threads: 0
xylude xylude is offline Offline
Light Poster

PHP / CSS incompatibility?

 
0
  #1
May 4th, 2008
I wrote a script in PHP that works fine on its own, but when inserted into a document containing CSS does not work properly. I am a newb with the PHP programming, and what I am trying to do is create a simple register/login script. Once the user has successfully logged in I used the "header" command to redirect them to the rest of the site. I tested the code in the page with CSS and the header command did not work. I also placed the code in a blank document and upon successful login It did work. Does anyone know if the CSS is what is causing the problem here? Also, the code placed in the non-css document was copied directly from the css document, and the extensions for both is .php.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: PHP / CSS incompatibility?

 
0
  #2
May 4th, 2008
The header function must be used before any output is printed, i.e before the opening HTML tag, make sure there is no HTML code or echo/print functions before the header one.
Last edited by Will Gresham; May 4th, 2008 at 2:45 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 27
Reputation: xylude is an unknown quantity at this point 
Solved Threads: 0
xylude xylude is offline Offline
Light Poster

Re: PHP / CSS incompatibility?

 
0
  #3
May 4th, 2008
There is nothing like that before the header function. As I said, the same exact code works on one page, but not on the one with the CSS layout. I am also using Dreamweaver CS3 if that helps.
Last edited by xylude; May 4th, 2008 at 3:07 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: PHP / CSS incompatibility?

 
0
  #4
May 4th, 2008
Are you adding the PHP code to the top of the HTML/CSS file or using an include function? Can you post the code here?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 27
Reputation: xylude is an unknown quantity at this point 
Solved Threads: 0
xylude xylude is offline Offline
Light Poster

Re: PHP / CSS incompatibility?

 
0
  #5
May 4th, 2008
It is running at the top of the document. I withheld all of the sql connection code because its a pain to hand copy it all ( i'm running the code on a separate machine than the one connected to the internet...).

Here is the code in a nutshell

<?php

sql connection stuff...

$username = $_POST['usern'];
$password = $_POST['pass'];

if($_POST['submit'])
{
$loginresults = mysql_query("SELECT *FROM registrations WHERE username = '$username' AND password = '$password' ")
or die (mysql_error());

$login_check = mysql_num_rows($loginresults);

if($login_check>0)
{
header('Location:http://localhost/portfolio.php');
}
}
Last edited by xylude; May 4th, 2008 at 4:17 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: PHP / CSS incompatibility?

 
0
  #6
May 4th, 2008
There doesnt seem to be a problem with the code, but for the header function, try to use a relative link and not http://localhost:
  1. header('Location:./portfolio.php');

On the page that it is not working is the PHP code on there or is it in a seperate file. Also, does the script return an error such as 'Headers already sent by...'?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 27
Reputation: xylude is an unknown quantity at this point 
Solved Threads: 0
xylude xylude is offline Offline
Light Poster

Re: PHP / CSS incompatibility?

 
0
  #7
May 4th, 2008
The PHP is on the page, not on a separate file. It also returns no errors, but that may be because it returns them underneath the CSS tables if it does.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: PHP / CSS incompatibility?

 
0
  #8
May 4th, 2008
Have a look at the source code through your browser to see if there are any errors hidden beneath tables/elements.

If there are not add something similar to the following to see if the SQL query is causing an issue:
  1. if($login_check>0) {
  2. header('Location:./portfolio.php');
  3. } else {
  4. echo 'Login Failed';
  5. }
Last edited by Will Gresham; May 4th, 2008 at 4:45 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 27
Reputation: xylude is an unknown quantity at this point 
Solved Threads: 0
xylude xylude is offline Offline
Light Poster

Re: PHP / CSS incompatibility?

 
0
  #9
May 4th, 2008
After creating yet another test page, this time with 3 simple html tables, it also does not work. I am now convinced that it is the tables that is botching my code.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 524
Reputation: Will Gresham is on a distinguished road 
Solved Threads: 86
Sponsor
Will Gresham's Avatar
Will Gresham Will Gresham is offline Offline
Posting Pro

Re: PHP / CSS incompatibility?

 
0
  #10
May 4th, 2008
So long as the PHP code comes before anything else in the file, the HTML/CSS should not effect it. If there is any HTML before the PHP then the headers are sent and cannot be modified with the header function.

Can you post the entire source here in [CODE ] [ /CODE] tags?
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC