| | |
PHP / CSS incompatibility?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: May 2008
Posts: 27
Reputation:
Solved Threads: 0
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.
•
•
Join Date: May 2008
Posts: 27
Reputation:
Solved Threads: 0
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');
}
}
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.
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:
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...'?
PHP Syntax (Toggle Plain Text)
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...'?
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:
If there are not add something similar to the following to see if the SQL query is causing an issue:
PHP Syntax (Toggle Plain Text)
if($login_check>0) { header('Location:./portfolio.php'); } else { echo 'Login Failed'; }
Last edited by Will Gresham; May 4th, 2008 at 4:45 pm.
![]() |
Other Threads in the PHP Forum
- Previous Thread: hello all
- Next Thread: Problem on runing Hello world with my php configuration HELP?
| Thread Tools | Search this Thread |
.htaccess alexa apache api array beginner beneath binary broadband broken cakephp checkbox class cms code convert cron curl database date display dynamic echo email emptydisplayvalue encode error fcc file files folder form forms function functions google howtowriteathesis href htaccess html image images include insert ip javascript joomla key keywords limit link login mail mail() memberships menu mlm multiple multipletables mysql mysql_real_escape_string network oop open passwords paypal pdf php provider query radio random redirect remote rss script search securephp server sessions smtp source space sql strip_tags syntax system table template tutorial update upload url user validator variable video voteup web youtube





