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 ?
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. Thanks for the help , much appreciated
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
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):
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);
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.
Change while($freehosthits = mysql_fetch_array($freehosthitsrs)) to while($freehostinghits = mysql_fetch_array($freehosthitsrs))
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 ?
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
Also you should take a look into how to prevent mysql injection attacks, since this is totally open to it