piniyini
10-18-2002, 05:57 PM
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 !
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 !