Hello, I am running a script with JQuery's $.POST the code is PHP though.It's just a basic login script
that that loads from the main login page.The script itself runs fine till the end when I try to direct the user into the control panel with the header() function and for some reason it gives me 2 pages on top of eachother.
Here is the script called by Ajax.

<?php
error_reporting(E_ALL ^ E_NOTICE);


$usernm = $_REQUEST['usernm'];
$passrd = $_REQUEST['passrd'];

include "../php_scripts/connection.php";
mysql_select_db ("database2")or die(mysql_error());
$query = mysql_query ("SELECT * FROM users WHERE '$usernm' = username AND '$passrd' = password ");
$row = mysql_fetch_array($query);
$usernm1 = $row['username'];
$passrd1 = $row['password'];
echo $usernm1;

    if (empty($usernm)&&empty($passrd))
    {echo " You must enter a username and a password. ";exit();}

    if ($usernm == "")
    { echo " Please type in a Username. ";exit();}

    if ($passrd == "")
    {echo " Please enter a password. ";exit();}


    if ($passrd != $passrd1)
    {echo " Password doesn't match this Username. ";exit();}

    if (($usernm == $usernm1) && ($passrd == $passrd1))
    { echo " Welcome $usernm1. ";
    header('Location:user_cp.php');
    exit();

    }
Member Avatar for diafol
 if (($usernm == $usernm1) && ($passrd == $passrd1)){ 
    echo " Welcome $usernm1. ";
    header('Location:user_cp.php');
    exit();
 }

You can't relocate after output (echo etc). It doesn't make sense anyway. If you need to show a message for say 3 seconds before relocating, you can do something like:

echo " Welcome $usernm1. You will be redirected to the control panel in 3 seconds";
header('Refresh:3 ; URL=user_cp.php');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.