A little help if you could :)

Discussion in 'PHP' started by Rivmedia, Oct 10, 2009.

  1. #1
    Ive been working with these files for 5 hours today, ive got nearly all of them sorted but this one is killing me

    Im getting this error :

    
    Notice: Undefined index: id in /home/bretr/public_html/freehostout.php on line 4
    Code (markup):
    This is the code :

    <?php
    error_reporting (E_ALL);
    require_once ("./includes/config.php");
    $hostid = $_GET['id'];
    $getfreehosthits = "SELECT Hits, HostingURL FROM freehosting WHERE HostingId='". $hostid ."'"; 
    $freehosthitsrs = mysql_query($getfreehosthits, $conn) or die (mysql_errno() . ": " . mysql_error()). "\n";
    while($freehosthits = mysql_fetch_array($freehosthitsrs))
    {
    	$hits = $freehostinghits['Hits'];
    	$url = $freehostinghits['HostingURL'];
    	$newhits = $hits + 1;
    	$updatehits = mysql_query("UPDATE freehosting SET Hits='". $newhits."' WHERE HostingId='". $hostid ."'");
    	mysql_query($updatehits, $conn);
    }
    mysql_free_result($freehosthitsrs);
    mysql_close($conn);
    header("Location:". $url. "");
    exit();
    ?>
    
    PHP:
    Any ideas ?
     
    Rivmedia, Oct 10, 2009 IP
  2. proxywhereabouts

    proxywhereabouts Notable Member

    Messages:
    4,027
    Likes Received:
    110
    Best Answers:
    0
    Trophy Points:
    200
    #2
    Like the error said, "id" is undefined.
    Did you find anywhere in the script "id" defined?
     
    proxywhereabouts, Oct 10, 2009 IP
  3. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $hostid = isset($_GET['id']) ? $_GET['id'] : 'id default value here';
    PHP:
     
    JAY6390, Oct 10, 2009 IP
  4. Rivmedia

    Rivmedia Notable Member

    Messages:
    2,306
    Likes Received:
    70
    Best Answers:
    0
    Trophy Points:
    210
    #4
    Sorry im not technically minded when it comes to coding , i normally just scrap my way around and find a resolution and normally find the answer.

    These are the 3 files that are in the script. Attached

    Also these are the tables in the database.

    [​IMG]

    Thanks for the help , much appreciated
     

    Attached Files:

    Rivmedia, Oct 10, 2009 IP
  5. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #5
    huh? all you have to do is modify line 4 to my code above, changing the 'id default value here' to whatever you want it to be by default if no id is given
     
    JAY6390, Oct 10, 2009 IP
  6. Rivmedia

    Rivmedia Notable Member

    Messages:
    2,306
    Likes Received:
    70
    Best Answers:
    0
    Trophy Points:
    210
    #6

    Yeah sorry didnt see your post until after , ive changed it to what you have put and now ive got these errors :

    Notice: Undefined variable: freehostinghits in /home/bretr/public_html/freehostout.php on line 9
    
    Notice: Undefined variable: freehostinghits in /home/bretr/public_html/freehostout.php on line 10
    
    Warning: Cannot modify header information - headers already sent by (output started at /home/bretr/public_html/freehostout.php:9) in /home/bretr/public_html/freehostout.php on line 17
    Code (markup):
     
    Rivmedia, Oct 10, 2009 IP
  7. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #7
    OK well I've done one for you. The reason you get undefined indexes is because you have things like $_GET['id'] which are only set if you pass id to the script. Since it's not being passed to the script however you're testing it, the id is not getting set and you're getting the undefined errors
    change your error reporting to
    error_reporting(E_ALL ^ E_NOTICE);
     
    JAY6390, Oct 10, 2009 IP
  8. Rivmedia

    Rivmedia Notable Member

    Messages:
    2,306
    Likes Received:
    70
    Best Answers:
    0
    Trophy Points:
    210
    #8
    Thanks Jay , ok the errors have now gone but the script isnt doing what its suppose to do.

    Basically this page : URL removed

    when you click on the link is suppose to redirect to the site , through them pages that i attached.

    The script is poor i admit , it was built a couple of years ago but it does do what its suppose to when it works. It was working recently until we moved hosts.
     
    Last edited: Oct 10, 2009
    Rivmedia, Oct 10, 2009 IP
  9. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Change
    while($freehosthits = mysql_fetch_array($freehosthitsrs))
    to
    while($freehostinghits = mysql_fetch_array($freehosthitsrs))
     
    JAY6390, Oct 10, 2009 IP
    Rivmedia likes this.
  10. Rivmedia

    Rivmedia Notable Member

    Messages:
    2,306
    Likes Received:
    70
    Best Answers:
    0
    Trophy Points:
    210
    #10
    Jay.....absolute star , I owe you a beer or two.

    Much appreciated
     
    Rivmedia, Oct 10, 2009 IP
  11. Rivmedia

    Rivmedia Notable Member

    Messages:
    2,306
    Likes Received:
    70
    Best Answers:
    0
    Trophy Points:
    210
    #11
    Just realised that because of this :

    $hostid = isset($_GET['id']) ? $_GET['id'] : '1';
    PHP:
    No matter what link you click it goes to the id 1 where before it was going to the correct id ?
     
    Rivmedia, Oct 10, 2009 IP
  12. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #12
    It will only go to id 1 if there is no id specified, otherwise it will go to the correct id. You can change it back and change back the error reporting
     
    JAY6390, Oct 10, 2009 IP
  13. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Also you should take a look into how to prevent mysql injection attacks, since this is totally open to it
     
    JAY6390, Oct 10, 2009 IP