Jump to content

[SOLVED] Header not redirecting


Vivid Lust

Recommended Posts

Hi all,

 

I made a script for a friend, it works find on my server but not on his (he uses PHP5)

 

Code:

 

<?php
require("db.php");
//connect to mysql
$link = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

//connect to db
mysql_select_db($dbname,$link) or die ('Error connecting to mysql') or die(mysql_error());

$t = $_GET['t'];

$sql ="SELECT * FROM tiny WHERE TinyUrl=\"$t\"";
$query=mysql_query($sql, $link)
or die(mysql_error());
while($row=mysql_fetch_assoc($query)){
$uri     =  $row['FullUrl'];
}
header("location: $uri");
?>
An error has occurred.

 

On mine, the header part works fine, however on his, it seems not to do anything, but the page just displays the "An error has ocurred". As far as I know there is no other error in the script. Just some weird header thing ( for me)

 

All help appreciated! Thanks guys

 

- Jake.

Link to comment
https://forums.phpfreaks.com/topic/144526-solved-header-not-redirecting/
Share on other sites

One, queries use single quotes, not double:

 

$sql ="SELECT * FROM tiny WHERE TinyUrl=\"$t\"";

Should be

$sql ="SELECT * FROM tiny WHERE TinyUrl='$t'";

 

That will cause an error. Two, it seems as though you expect more than 1 item returned, but you are only using the last item, try this:

 

$sql ="SELECT `FullUrl` FROM tiny WHERE TinyUrl='$t'";
$query=mysql_query($sql, $link) or die("ERROR IN SQL {$sql} \n Mysql Reutrned: " . mysql_error());
$uri = mysql_result($query, 0);

 

Change those items and see if it works.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.