Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    United Kingdom
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    useing MySQL to redirect

    Hello guys,

    I've been trying to redirect using MySQL but I havnt been successful. Also, I'm self taught (meaning I dont know much).

    This is what I'm trying to do.
    I've got a file called "click.php", and i want it to redirect people by adding a querystring to it. So if I have click.php?id=2 it would go to, say, hotmail.com.
    I've got a table called links, inside it I've got 2 fields, 1 called id, the other called to. I am trying to redirect depending on the id.

    I got a code from a webpage (which was used for something else) and modified it, but it doesnt work.

    Help ! Here's the code :

    <?php header('Cache-Control:no-cache,no-store,must-revalidate');header('Pragma:no-cache');

    $host = "hostname";
    $user = "user";
    $pass = "pass";
    $database = "thewizsite_uk_db";
    $table = "links";

    // Connecting to the Database
    $connect = @mysql_connect($host, $user, $pass) or die("could not connect to server");

    // Selecting the Database for use
    $db_select = @mysql_select_db($database) or die("could not select the database");

    // Compose SQL command
    $SQL = "SELECT to
    FROM $table
    WHERE (id='$id')
    ";

    // Query the Database
    $result = @mysql_query($SQL) or die("could not complete your query");

    // Loop the results
    // Note, results are returned as an
    // Array - we cannot just print it out.
    while($row = @mysql_fetch_array($result)) {
    $to = $row["to"];
    header('location:$to');
    } ;
    exit; ?>

    I've been trying different stuff for ages, so any help will be much appreciated !

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A quick scan through ....

    Single quotes in php output will NOT attribute values to vars, only double quotes will

    $var = 'value';
    echo '$var'; ------------> $var
    echo "$var"; -----------> value

    So the header('location:$var') wouldn't attribute the value of $var in the header output. Just use double quotes there instead.

    header("location: $to");

    should do the trick if your query is working properly.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #3
    New Coder
    Join Date
    Aug 2002
    Location
    United Kingdom
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nah, that doesnt work.

    Anyone else care to help?

  • #4
    New Coder
    Join Date
    Aug 2002
    Location
    United Kingdom
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've got the code, I was messing around with it and it worked. Dont understand a word of it though.

    Thanks all the same guys.

    Bye.


  •  

    Posting Permissions

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