0

I'm trying to get my config.php file to work but everytime i use it with my login.php it just gives me a white page rather than continuing through my login.php file towards my members.php page. I put my connection info into my login.php script and it works properly listed below is what i been trying to do.

config.php

<?php 

$con = mysql_connect("mysql","DBUSER","DBPASS");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("DBNAME", $con);

/* WHAT I ORIGINALLY WANTED TO USE
$localhost = "mysql";
$dbuser = "DBUSER";
$dbpass = "DBPASS";
$dbname = "DBNAME";

$connect = mysql_connect($localhost, $dbuser, $dbpass);
mysql_select_db("$dbname", $connect); 
*/

?>

login.php

<?php
// I ALSO USED includes"config.php";
require("config.php");

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


$query = mysql_query("SELECT * FROM member WHERE username = '$username' AND password =       '$password'");
$data = mysql_fetch_assoc($query);

if(mysql_num_rows($query)){
session_start();
$_SESSION['username'] = $data['username'];
header("Location: members.php");
exit;
}

header("Location: index.php");

?>

I'm new to PHP so don't laugh at my code please thanks for the help!

5
  • 3
    white page of death = error but you have error checking off or not displaying. Commented Oct 10, 2012 at 23:58
  • Any errors? Check your error logs Commented Oct 10, 2012 at 23:58
  • 1
    includes should be include("config.php"); php.net/manual/en/function.include.php Commented Oct 10, 2012 at 23:59
  • 1
    Don't use the mysql_* api anymore, it's being deprecated. Commented Oct 11, 2012 at 0:00
  • Please don't use mysql_* functions in new code. They were removed from PHP 7.0.0 in 2015. Instead, use prepared statements via PDO or MySQLi. See Why shouldn't I use mysql_* functions in PHP? for more information. Commented Oct 11, 2012 at 0:11

2 Answers 2

4

On top of your code turn on errors:

ini_set("display_errors","On");

and make sure you can see your mysql errors:

$query = mysql_query(...) or die("Error: ".mysql_error());

And one last thing: although mysql_* functions are being deprecated, if you use them always escape your data before you use it in your query; you can be victim of SQL injection.

Sign up to request clarification or add additional context in comments.

5 Comments

Ok ill give that a try thanks I'll try those and look into sql injections!
my two msgs when I add ini_set are:Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /php/config.php:21) in /php/login.php on line 13 Warning: Cannot modify header information - headers already sent by (output started at /php/config.php:21) in /andrew/login.php on line 15
What this means is that you are setting your headers after they are already sent. move the session_start in your config maybe.
@AndrewL one little trick will be to remove the closing php tag ?> in your config file. sometimes a space is added and the header is sent.
It works! I removed the ?> and made sure i used include... instead of includes..and bam works like a charm! thanks!
0

try to use:

include "config.php";

it should be include not includes

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.