Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.