1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Header(Location)

Discussion in 'HTML & Website Design' started by toshibata, Dec 7, 2011.

  1. #1
    Hello,

    So I try to use header( "Location:" .$row['url'] ); in order to redirect to a url saved in my database however all I get is a blank page. Any ideas?


    <?php
    
    include("config.php");
    session_start();
    
    
    if($_SERVER["REQUEST_METHOD"] == "POST")
    {
    // username and password sent from form 
    
    
    $myusername=addslashes($_POST['username']); 
    $mypassword=addslashes($_POST['password']); 
    $mypassword=md5($mypassword);
    
    
    $sql="SELECT id FROM users WHERE username='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);
    $row=mysql_fetch_array($result);
    $active=$row['active'];
    
    
    $count=mysql_num_rows($result);
    
    
    
    
    // If result matched $myusername and $mypassword, table row must be 1 row
    if($count==1)
    {
    session_register("myusername");
    $_SESSION['login_user']=$myusername;
    
    
    header( "Location:" .$row['url'] );
    exit;
    }
    else 
    {
    $error="Your Login Name or Password is invalid";
    }
    }
    ?>
    Code (markup):
     
    toshibata, Dec 7, 2011 IP
  2. qhm

    qhm Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What's the url for that blank page?
     
    qhm, Dec 8, 2011 IP
  3. kids

    kids Active Member

    Messages:
    411
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    68
    #3
    It's maybe sql excute but return nothing. So before redirect you try to print out (echo command) $row['url']. You will have your own way to go. That's all.
     
    kids, Dec 8, 2011 IP
  4. alimoula

    alimoula Peon

    Messages:
    114
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yes forst check whether sql is giving some value or not fort echo your variable and check
     
    alimoula, Dec 8, 2011 IP
  5. toshibata

    toshibata Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The blank page is the same as the initial one which in this case is login.php.

    The sql query is returning the correct values, however the redirect does not happen for some reason
     
    toshibata, Dec 8, 2011 IP