NameSilo

Anyone see a problem here?

SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
Namecheap AuctionsNamecheap Auctions
Watch

PoorDoggie

Soon to be RICHdoggie!VIP Member
Impact
18
PHP:
<?php
if(isset($_SERVER['QUERY_STRING'])){
  if( ( strlen($_SERVER['QUERY_STRING']) == 4 ) ){
    $qs = $_SERVER['QUERY_STRING'];
    include(config.php); // connect to DB and stuff...
    // now we need to find the id...
    $sql = "SELECT * FROM 6yd_short_url WHERE id='$qs'";
    $result = mysql_query($sql);
    $num = mysql_num_rows($result);
    if($num > 0){
      $redirect = mysql_fetch_array($result);
      header("location: ".$redirect['url']);
    }
    else{
      header("location: shorturl");
    }
  }
}
?>
This is in the index.php page of my new site - http://6yd.net.

Now, if I put in http://6yd.net/?c43c (which is in my database - redirecting to http://poordoggie.co.uk) it dosen't seem to find it, and instead redirects to http://6yd.net/shorturl (which redirects back to http://6yd.net/index.php)... I don't know what is wrong, there don't seem to be any error messages... can anyone help?

Thanks
Tom
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
I strongly recommand you do not do it that way. Probley doesn't work because your host has Registered Globals off.

I would do it.

PHP:
<?php
if(isset($_GET['q'])){
  if( ( strlen($_GET['q']) == 4 ) ){
    $qs = $_GET['q'];
    include(config.php); // connect to DB and stuff...
    // now we need to find the id...
    $sql = "SELECT * FROM 6yd_short_url WHERE id='$qs'";
    $result = mysql_query($sql);
    $num = mysql_num_rows($result);
    if($num > 0){
      $redirect = mysql_fetch_array($result);
      header("location: ".$redirect['url']);
    }
    else{
      header("location: shorturl");
    }
  }
}
?>

Have it do http://6yd.net/?q=c43c

iNod.
 
0
Close
hmm...

$_SERVER['QUERY_STRING'] can be echoed out, so that works perfectly.

Substituting my code for yours dosen't help. http://6yd.net/?q=c43c still dosen't work. I think that the problem is with the MYSQL. How would I check to see if it is conecting to the database?

This is config.php (with details removed):
PHP:
$dbc = mysql_connect("host", "username", "password");
mysql_select_db("database",$dbc);
 
0
Close
Add
or die(mysql_error()); to the end like
PHP:
 $dbc = mysql_connect("host", "username", "password")or die(mysql_error());;
mysql_select_db("database",$dbc)or die(mysql_error());;

iNod.

Try this
Change your SQL Query to

PHP:
    $sql = "SELECT * FROM 6yd_short_url WHERE id='$qs' LIMIT 1";

This is what is the problem
PHP:
    if($num > 0){
      $redirect = mysql_fetch_array($result);
      header("location: ".$redirect['url']);
    }
    else{
      header("location: shorturl");
    }

It redirects to shorturl or back to the main page as you said.

So. First try and remove the if command and see if it works correctly.
Than try replacing $num with the actual command so
PHP:
if(mysql_num_rows($result) < 0) {
do stuff
}else{
do stuff
}

iNod.
 
1
Close
thanks for your help! :)

The problem was that I needed to put "config.php" in quotes to get it to work! :lol:
 
0
Close
LOL.. I was actually just typing that.

iNod.
 
0
Close
I gave you some rep for your troubles! :) Thanks
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back