Dynadot โ€” .com Registration $8.99

Anyone see a problem here?

Spaceship Spaceship
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
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
•••
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
•••
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
•••
thanks for your help! :)

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

iNod.
 
0
•••
I gave you some rep for your troubles! :) Thanks
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back