SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast spsalter's Avatar
    Join Date
    Apr 2005
    Location
    A little to the left
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    header redirect, multiple pages

    I am using what should be a simple script to redirect a user based on their login to a predefined location which is stored in the database. Each user will have a unique directory assigned. The problem is, I can only get the page to refresh when I submit the form. I have done some error checking and the correct url is being pulled, just not applied. Any ideas?
    Code:
    <?
    if (isset($_POST['submit'])) {
    $MYSQL_HOST = "...";
    $db_name="...";
    $connection=@mysql_connect(...) or die("Couldn't connect to $MYSQL_HOST.");
    $db=@mysql_select_db($db_name,$connection) or die("Couldn't select database.");
    $loginsql="SELECT redirect_url FROM user WHERE id='".$_POST['id']."' and pass='".$_POST['pass']."'";
    $get_user=@mysql_query($loginsql);
    
    $q=@mysql_num_rows($get_user);
    
    if (mysql_num_rows($get_user) >0)
    {
    header("Location: " . redirect_url);
    	} else {
    echo "<p>Login Failure: An error occured, please verify your username and password are correct. Hit the Back button in your browser and try again.</p>";
    }
    
    function myquery ($loginsql) {
            $result = mysql_query($loginsql);
            if (mysql_errno())
                echo "MySQL error ".mysql_errno().": ".mysql_error()."\n<br>When executing:<br>\n$loginsql\n<br>";
            return $result;
        }
    
    }
    ?>

  2. #2
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    header("Location: " . redirect_url);
    you didnt get the url from the query. redirect_url is nothing.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    Indonesia - Bali
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think so.
    redirect_url act as what? u didn't have to define redirect_url as a constant or a variable?

    i think your existing code will run if u define redirect_url

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When i saw your code, the function that you have defined is not used anywhere. Avoid using @ in front of the functions because it ignores the warnings which makes you difficult to get the errors.

    Do you mean that each user's URL will be different and you want to redirect them on selection?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what do you want?
    maybe you can use more than 2 pages bro.

    <?php
    if (isset(SOMETHING)) {
    require_once('file.php');
    } else require_once('ok'.php');
    ?>

    try it

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry bro, but i think if you call a function it should be in java script, not in php tag

    use script tag

    <script>

    function print() {
    alert('something');
    }

    </script>

    is function can be called in php tag??

  7. #7
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cell_oz2 View Post
    is function can be called in php tag??
    You can call javascript function from within PHP tag but you need to write like this:
    PHP Code:
    echo '<script>callMyFunction();</script>'
    This will call callMyFunction() .
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  8. #8
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, thanks

  9. #9
    SitePoint Enthusiast spsalter's Avatar
    Join Date
    Apr 2005
    Location
    A little to the left
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like I got it. Thanks all for the help

    Code:
    $get_user=mysql_query($loginsql);
    
    $q=mysql_num_rows($get_user);
    
    if (mysql_num_rows($get_user) >0)
    {
    while ($row=mysql_fetch_array($get_user)) {
    $redirect_url = $row['redirect_url'];
    }
    header("Location: " . $redirect_url);
    	} else {
    echo "<p>Login Failure: An error occured, please verify your username and password are correct. Hit the Back button in your browser and try again.</p>";
    }
    
    function myquery ($loginsql) {
            $result = mysql_query($loginsql);
            if (mysql_errno())
                echo "MySQL error ".mysql_errno().": ".mysql_error()."\n<br>When executing:<br>\n$loginsql\n<br>";
            return $result;
        }
    
    }

  10. #10
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rajug View Post
    You can call javascript function from within PHP tag but you need to write like this:
    PHP Code:
    echo '<script>callMyFunction();</script>'
    This will call callMyFunction() .
    It's not actually calling it. Printing it to the page and calling a function are two different things. The only way to call a Javascript function directly is with Javascript on the client. PHP merely prints it, and doesn't know or care what it is.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •