Jump to content
MakeWebGames

Notice: Undefined Index: fd ??? Help please


Recommended Posts

Posted

i keep getting an error notice on my practice website about an undefined index known as fd. heres the code.

 

<?php
define("LOAD_START", microtime(true));
class headers {
function startheaders() {
$userid=$_SESSION['userid'];
global $ir, $set;

if ($ir['fd']==0) { $enperc=(int) ($ir['energy']/$ir['maxenergy']*100); }
if ($ir['fd']==1) { $enperc=(int) ($ir['energy']/$ir['maxenergy']*150); }
$wiperc=(int) ($ir['will']/$ir['maxwill']*100);
$experc=(int) ( $ir['exp']/$ir['exp_needed']*100);
$brperc=(int) ($ir['brave']/$ir['maxbrave']*100);
$hpperc=(int) ($ir['hp']/$ir['maxhp']*100);
if($ir['max_power'] > 0 && $ir['power'] > 0)
{ $power=(int)  ($ir['power']/$ir['max_power']*100); }
else { $power=(int) (0); }
if($ir['mine_needed'] > 0 && $ir['mine_exp'] > 0)
{ $minexp=(int) ($ir['mine_exp']/$ir['mine_needed']*100); }
else { $minexp =(int) (0); }
$enopp=100-$enperc;
$wiopp=100-$wiperc;
$exopp=100-$experc;
$bropp=100-$brperc;
$hpopp=100-$hpperc;
$pow=100-$power;
$minex=100-$minexp;
$_GET['ID'] = abs(@intval($_GET['ID']));
$_GET['viewforum'] = abs(@intval($_GET['viewforum']));
$_GET['viewtopic'] = abs(@intval($_GET['viewtopic']));
Posted

could you give me an example or tell me how i would do that. heres my globals.php code

 

<?php
/*---------------------------------
--   MCCodes 2.0
--   By Dabomstew
---------------------------------*/
session_start();
ob_start();
if(get_magic_quotes_gpc() == 0)
{
 foreach($_POST as $k => $v)
 {
   $_POST[$k]=addslashes($v);
 }
 foreach($_GET as $k => $v)
 {
   $_GET[$k]=addslashes($v);
 }
}

require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";

include "config.php";
global $_CONFIG;
define("MONO_ON", 1);
require "class/class_db_{$_CONFIG['driver']}.php";
$db=new database;
$db->configure($_CONFIG['hostname'],
$_CONFIG['username'],
$_CONFIG['password'],
$_CONFIG['database'],
$_CONFIG['persistent']);
$db->connect();
$c=$db->connection_id;
$set=array();
$settq=$db->query("SELECT * FROM settings");
while($r=$db->fetch_row($settq))
{
$set[$r['conf_name']]=$r['conf_value'];
}
$domain=$_SERVER['HTTP_HOST'];

global $jobquery, $housequery;
if($jobquery)
{
$is=$db->query("SELECT u.*,us.*,j.*,jr.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid LEFT JOIN jobs j ON j.jID=u.job LEFT JOIN jobranks jr ON jr.jrID=u.jobrank WHERE u.userid=$userid");
}
else if($housequery)
{
$is=$db->query("SELECT u.*,us.*,h.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid LEFT JOIN houses h ON h.hWILL=u.maxwill WHERE u.userid=$userid");
}
else
{
$is=$db->query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid");
}
$ir=$db->fetch_row($is);
if($ir['force_logout'])
{
$db->query("UPDATE users SET force_logout=0 WHERE userid=$userid");
session_unset();
session_destroy();
header("Location: login.php");
exit;
}
global $macropage;
if($macropage && !$ir['verified'] && $set['validate_on']==1)
{
header("Location: macro1.php?refer=$macropage");
exit;
} 
check_level();
$h = new headers;
$h->startheaders();
$fm=money_formatter($ir['money']);
$cm=money_formatter($ir['crystals'],'');
$lv=date('F j, Y, g:i a',$ir['laston']);
global $atkpage;
if($atkpage)
{
$h->userdata($ir,$lv,$fm,$cm,0);
}
else
{
$h->userdata($ir,$lv,$fm,$cm);
}
global $menuhide;
if(!$menuhide)
{
$h->menuarea();
}

?>
Posted

Okay scratch that last post seems to already do it, providing you have a fd column in your users database table.

if ($ir['fd']==0) { $enperc=(int) ($ir['energy']/$ir['maxenergy']*100); }<br />

if ($ir['fd']==1) { $enperc=(int) ($ir['energy']/$ir['maxenergy']*150); }<br />

To:

$enperc = (isset ($ir['fd'])) ? (int) ($ir['energy']/$ir['maxenergy']*150) : (int) ($ir['energy']/$ir['maxenergy']*100);

P.S: Welcome. :)

  • Like 1
Posted

thank u so much. it cleared up 2 off the undefined errors on the web page when i hit login. ima try see if i can clear the rest up. Thank u ur awesome! is there like a rating system or something on here.

Posted (edited)

There's a little star thing at the bottom of peoples posts.

The reason it comes up is because the variable usually a _GET within MCCodes isn't actually defined until you define it, so for example you visit say explore and your explore is set up like


if ($_GET['shopping']) {
// Show shopping centre
} else {
//Show normal shops
}

You visit that page you'll get normal shops and a Undefined notice for shopping, but if you visit the shopping centre explore.php?shopping the notice will be removed.

To solve this;

if (isset ($_GET['shopping']) ) {
//Show shopping centre
} else { 
//Show normal..
}
Edited by Djkanna
Posted

o okay yea i recognize the isset i actually used that alot to clear up alot of notices on my log-in page that i USED to have :) but yea i'll the isset on my next notice that i have. its a undefined on max_power & mine_needed on lines 1 & 4.

if($ir['max_power'] > 0 && $ir['power'] > 0)
{ $power=(int)  ($ir['power']/$ir['max_power']*100); }
else { $power=(int) (0); }
if($ir['mine_needed'] > 0 && $ir['mine_exp'] > 0)
{ $minexp=(int) ($ir['mine_exp']/$ir['mine_needed']*100); }
else { $minexp =(int) (0); }
Posted (edited)

Are those fields actually in your database users table? I don't see why it's coming up for them.

But you can do

$power = (isset($ir['max_power']) > 0 && isset($ir['power']) > 0) ? (int) ($ir['power']/$ir['max_power']*100) : 0;
$minexp = (isset($ir['mine_needed']) > 0 && isset($ir['mine_exp']) > 0) ? (int) ($ir['mine_exp']/$ir['mine_needed']*100) : 0;

You wouldn't actually need the > 0 but hey. :P

Edited by Djkanna
Posted

when i tried isset i got a parse error. & now that u mentioned it i didnt see those in my db lol. im actually re-building a text based mmorpg a friend of mine used to have. now that i look it the db user_stats its IQ,Labour,Guard, Agility, & Strength. & in users table here some thats related to stats; exp, energy, will, brave, hp, & crime exp. so now im wondering do the 'power' really belong? but im sure it dose cuz my friend currently has a running website so im sure he wouldnt make a amateur mistake like that.

Posted

Well just in-case, add those required fields in the users table (and/or) users stats table and undo what's been done see if the error remains, I believe that's where the problem lies, as it only grabs from the users table and users stats (sometimes houses and jobs) and uses the returned results in the form of $ir :)

Posted

yup so adding them to the db worked. now ima try see if i can figure out how to fix an undefined constant. im loving all these new things im learning.

Posted

ah! but i had did something else before i seen this post & the notice disappeared. i just added quotes around male & female and it worked. the undefined constants WERE for male & female part of the code but i got rid of it now. i just cleared a good amount of notices using what u just taught me. im only 16 and currently trying self teach myself using w3schools and anything else i can find.

Posted
ah! but i had did something else before i seen this post & the notice disappeared. i just added quotes around male & female and it worked. the undefined constants WERE for male & female part of the code but i got rid of it now. i just cleared a good amount of notices using what u just taught me. im only 16 and currently trying self teach myself using w3schools and anything else i can find.

Awesome, PHP manual is a handy thing to have. :)

php.net/function_name

example

php.net/isset

:)

Posted

okay i cant fix the undefined on this stelth thing. i fixed it on the http_x_forwarded tho.

function userdata($ir,$lv,$fm,$cm,$dosessh=1)
{
global $db,$c,$userid, $set;
$IP = (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
   ?  $_SERVER['HTTP_X_FORWARDED_FOR']
   :  $_SERVER['REMOTE_ADDR'];
if($ir['stelth'] == 1) {
$db->query("UPDATE users SET lastip='$IP' WHERE userid=$userid");
}
else {
$db->query("UPDATE users SET laston=unix_timestamp(),lastip='$IP' WHERE userid=$userid");
}
Posted

ah so my hunch was right. i just didnt think it was right because i didnt think so many tables would go in a users table. i have 60 tables so far.

Posted
ah so my hunch was right. i just didnt think it was right because i didnt think so many tables would go in a users table. i have 60 tables so far.

Yes the users table is unorganized by default.

Posted (edited)

Nope, I did the same thing you're doing now, just teaching myself via tutorials on the web (like w3Schools) and the PHP manual, and help from friends/community members.

:)

If you grab a script that's been purposely built to fail, it has an error or two somewhere within it, trying to get it working again is a great learning experience for correct usage of things etc.

Also gets you familiar with debugging, which is rather common in places.

Edited by Djkanna
Posted

ah cool so i take it im on the right track. but i came across another WIERD situation. if i add burntime to db it will always say your house will be repaired in # minutes. & if i add travel time to db it wont let me do nothing and be like your are traveling for 0 minutes. is there a way to keep them in db but have them inactive when the value is 0. this is travel time code

if(isset($ir['ttime']) > 0)
{
$q=mysql_query("SELECT * FROM users WHERE userid=$userid",$c);
$r=mysql_fetch_array($q);
die("<br><br><center><img src='airplane.jpg'><br/><b>You are traveling. You have {$ir['ttime']} minutes left. Sit back and enjoy the flight.<br/>We reccomend you <a href='http://www.criminalisland.com/chat.php' target='_new'>CLICK HERE</a> and connect to the chatroom while you wait!</center><br />
");
}

This is burntime code

if(!$ir['BurnTime'] && $ir['BurnHouse']>=100)
{
print "<b><font color=red>Your house is ready to be repaired click <a href='BRepair.php'><font color=green>Here</font></a> to Finalize.</font></b><br>";
}
Posted (edited)

ok so i examined the code & fixed the burntime thing. i just had to remove isset

edit: i fixed both now. it was same fix, just had to remove isset.

Edited by Daron
Posted
ok so i examined the code & fixed the burntime thing. i just had to remove isset

edit: i fixed both now. it was same fix, just had to remove isset.

Yes isset() shouldn't be used there, well done for finding the solution yourself. :)

Posted

ok 1st of all i just wanna let u know u been very helpful. and using what u told me i cleared every notice on my 1st page except 1 that i cant get. its saying Undefined Offset: 0

$array_gete = array($_GET);
while ($tick = current($array_gete)) {
  $thekey = key($array_gete);
  $_GET[$thekey] = str_replace("=", "", htmlspecialchars($_GET[$thekey]));
  next($array_gete);
}

line 4 is the line that has the undefined offset: 0

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.   Paste as plain text instead

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