Jump to content
MakeWebGames

Crafting Error


Recommended Posts

Here is the error -

 

A non-critical error has occurred. Page execution will continue. Below are the details:
PHP Notice: Undefined variable: needs (8)

Line executed: /home/samurai/public_html/craft.php:178

A non-critical error has occurred. Page execution will continue. Below are the details:
PHP Notice: Undefined variable: items_needed (8)

Line executed: /home/samurai/public_html/craft.php:178

 

Line 178 -

$items_needed .= $needs .",";

 

 

I tried everything to fix, however I cannot!

Link to comment
Share on other sites

Here is the error -

 

A non-critical error has occurred. Page execution will continue. Below are the details:
PHP Notice: Undefined variable: needs (8)

Line executed: /home/samurai/public_html/craft.php:178

A non-critical error has occurred. Page execution will continue. Below are the details:
PHP Notice: Undefined variable: items_needed (8)

Line executed: /home/samurai/public_html/craft.php:178

 

Line 178 -

$items_needed .= $needs .",";

 

 

I tried everything to fix, however I cannot!

can you post line 60 - 180 please

Link to comment
Share on other sites

Did you maybe delete an item after adding it to the crafting list?

Since when does php say " Undefined variable " ? variables can be assigned to any value and don't necessarily have to be used and can be used later on im still thinking

Link to comment
Share on other sites

Here is the error -

A non-critical error has occurred. Page execution will continue. Below are the details:
PHP Notice: Undefined variable: needs (8)

Line executed: /home/samurai/public_html/craft.php:178

A non-critical error has occurred. Page execution will continue. Below are the details:
PHP Notice: Undefined variable: items_needed (8)

Line executed: /home/samurai/public_html/craft.php:178

Line 178 -

$items_needed .= $needs .",";

I tried everything to fix, however I cannot!

Set the items_needed variable prior to line 178.

So say if 178 is in a loop you'd do something like:

//[...]
$items_needed = '';

foreach ( $arr as $key => $val ) {
 //code
 $items_needed .= $needs . ",";
 //code
}
//[...]
Link to comment
Share on other sites

function craft() {
global $ir, $h, $db, $userid;
   $already_crafting = $db->query("SELECT `userid`,`item_given` FROM `craft_inprogress` WHERE `userid`={$userid}");
   if($db->num_rows($already_crafting)) {
       echo "<div class='error'>You are already crafting!</div>";
       exit($h->endpage());
   }
   if(!$_GET['id']) {
       index();
       exit($h->endpage());
   }
   $_GET['id'] = filter_var($_GET['id'], FILTER_VALIDATE_INT) ? abs( (int) $_GET['id']) : 0;
   $exist = $db->query("SELECT * FROM `craft_mod` WHERE `id`={$_GET['id']}");
   if($db->num_rows($exist) == 0) {
       echo "<div class='error'>We couldn't find the blueprints for the item you wanted to craft!</div>";
       exit($h->endpage());
   }
   $r = $db->fetch_row($exist);

   if($r['donator'] AND $ir['donatordays'] == 0) {
       echo "<div class='error'>You cannot craft this item!</div>";
       exit($h->endpage());
   }

   $item_given = $db->fetch_row($db->query("SELECT `itmname` FROM `items` WHERE `itmid`={$r['item_given']}"));
   ?>
   <h3>Crafting;  <?php echo $item_given['itmname']; ?></h3>
   <?php
     $can_craft = TRUE;
     $ex = explode(",", $r['items_needed']);
     $qty = explode(",", $r['qty_needed']);
     $n = 0;
     foreach($ex as $i) {
        $get_items_needed = $db->query("SELECT `itmname` FROM `items` WHERE `itmid`={$i}");
        $t = $db->fetch_row($get_items_needed);

        $do_they_have = $db->query("SELECT `inv_itemid` FROM `inventory` WHERE `inv_userid`={$userid} AND `inv_itemid`={$i} AND `inv_qty`>={$qty[$n]}");
        if($db->num_rows($do_they_have) == 0) {
            $needs = $t['itmname']." x ". $qty[$n];
            $can_craft = FALSE;
        }

        $items_needed = '';

foreach ( $n as $n => $n ) {
 //code
 $items_needed .= $needs . ",";
 //code
}
        $n++; 













     }
     if(isset($items_needed)) {
         $criteria = "You need the following items;<br />".$items_needed."<br />";
     }
     unset($n);

     if($r['level_needed'] > $ir['level']) { 
         $criteria .= "You need to advance in level before you can craft this item<br />";
         $can_craft = FALSE;
     }
     if($r['money_needed'] > $ir['money']) {
         $criteria .= "You need more money before you can craft this item<br />";
         $can_craft = FALSE;
     }
     if($r['coins_needed'] > $ir['coins']) {
         $criteria .= "You need more coins before you can craft this item<br />";
         $can_craft = FALSE;
     }
     if($r['minimum_days'] > $ir['daysold']) {
         $criteria .= "You need to wait ". $ir['minimum_days'] - $ir['daysold'] ." days before you can craft this item<br />";
         $can_craft = FALSE;
     }
     if($r['course_needed']) { 
         $get_course = $db->query("SELECT `name` FROM `education_courses` WHERE `ID`={$r['course_needed']}");
         $co = $db->fetch_row($get_course); 
         $have_i_completed = $db->query("SELECT `userid` FROM `education_coursesdone` WHERE `userid`={$userid} AND `courseid`={$r['course_needed']}");
         if($db->num_rows($have_i_completed) == 0) {
             $criteria .= "You need to complete the ".$co['name']." course before you can craft this item<br />";
             $can_craft = FALSE;
         }
     }

     if($can_craft) {
         if($r['time_to_complete'] > 0) {
     ?>
           <div class='notice'>The <?php echo $item_given['itmname']; ?> is in progress of crafting!</div>
     <?php
           $time = time() + $r['time_to_complete'];
           $db->query("INSERT INTO `craft_inprogress` (`userid`,`item_given`,`endtime`) VALUES ({$userid}, {$r['item_given']}, {$time})");
         } else {
     ?>
           <div class='notice'>You have successfully crafted <?php echo $item_given['itmname']; ?>. You put it in your inventory!</div>
     <?php
           item_add($userid, $r['item_given'], 1);
         }
         $ex = explode(",", $r['items_needed']);
         $qty = explode(",", $r['qty_needed']);
         $n = 0;
         foreach($ex as $i) {
            item_remove($userid, $i, $qty[$n]);
            $n++;
         } 
         unset($n);
         unset($ex);
         unset($qty);
         if($r['money_needed']) { $db->query("UPDATE `users` SET `money`=`money`-{$r['money_needed']} WHERE `userid`={$userid}"); }
         if($r['coins_needed']) { $db->query("UPDATE `users` SET `coins`=`coins`-{$r['coins_needed']} WHERE `userid`={$userid}"); }
         exit($h->endpage());
     } else {
         echo "<div class='error'><strong>You cannot craft this item, for the following reasons;</strong><br />".$criteria."</div>";
         exit($h->endpage());
     }
}

 

Something like that?

Sorry I don't understand...But I am trying xD

Link to comment
Share on other sites

function craft() {
global $ir, $h, $db, $userid;
   $already_crafting = $db->query("SELECT `userid`,`item_given` FROM `craft_inprogress` WHERE `userid`={$userid}");
   if($db->num_rows($already_crafting)) {
       echo "<div class='error'>You are already crafting!</div>";
       exit($h->endpage());
   }
   if(!$_GET['id']) {
       index();
       exit($h->endpage());
   }
   $_GET['id'] = filter_var($_GET['id'], FILTER_VALIDATE_INT) ? abs( (int) $_GET['id']) : 0;
   $exist = $db->query("SELECT * FROM `craft_mod` WHERE `id`={$_GET['id']}");
   if($db->num_rows($exist) == 0) {
       echo "<div class='error'>We couldn't find the blueprints for the item you wanted to craft!</div>";
       exit($h->endpage());
   }
   $r = $db->fetch_row($exist);

   if($r['donator'] AND $ir['donatordays'] == 0) {
       echo "<div class='error'>You cannot craft this item!</div>";
       exit($h->endpage());
   }

   $item_given = $db->fetch_row($db->query("SELECT `itmname` FROM `items` WHERE `itmid`={$r['item_given']}"));
   ?>
   <h3>Crafting;  <?php echo $item_given['itmname']; ?></h3>
   <?php
     $can_craft = TRUE;
     $ex = explode(",", $r['items_needed']);
     $qty = explode(",", $r['qty_needed']);
     $n = 0;
     foreach($ex as $i) {
        $get_items_needed = $db->query("SELECT `itmname` FROM `items` WHERE `itmid`={$i}");
        $t = $db->fetch_row($get_items_needed);

        $do_they_have = $db->query("SELECT `inv_itemid` FROM `inventory` WHERE `inv_userid`={$userid} AND `inv_itemid`={$i} AND `inv_qty`>={$qty[$n]}");
        if($db->num_rows($do_they_have) == 0) {
            $needs = $t['itmname']." x ". $qty[$n];
            $can_craft = FALSE;
        }

        $items_needed = '';

foreach ( $n as $n => $n ) {
 //code
 $items_needed .= $needs . ",";
 //code
}
        $n++; 













     }
     if(isset($items_needed)) {
         $criteria = "You need the following items;<br />".$items_needed."<br />";
     }
     unset($n);

     if($r['level_needed'] > $ir['level']) { 
         $criteria .= "You need to advance in level before you can craft this item<br />";
         $can_craft = FALSE;
     }
     if($r['money_needed'] > $ir['money']) {
         $criteria .= "You need more money before you can craft this item<br />";
         $can_craft = FALSE;
     }
     if($r['coins_needed'] > $ir['coins']) {
         $criteria .= "You need more coins before you can craft this item<br />";
         $can_craft = FALSE;
     }
     if($r['minimum_days'] > $ir['daysold']) {
         $criteria .= "You need to wait ". $ir['minimum_days'] - $ir['daysold'] ." days before you can craft this item<br />";
         $can_craft = FALSE;
     }
     if($r['course_needed']) { 
         $get_course = $db->query("SELECT `name` FROM `education_courses` WHERE `ID`={$r['course_needed']}");
         $co = $db->fetch_row($get_course); 
         $have_i_completed = $db->query("SELECT `userid` FROM `education_coursesdone` WHERE `userid`={$userid} AND `courseid`={$r['course_needed']}");
         if($db->num_rows($have_i_completed) == 0) {
             $criteria .= "You need to complete the ".$co['name']." course before you can craft this item<br />";
             $can_craft = FALSE;
         }
     }

     if($can_craft) {
         if($r['time_to_complete'] > 0) {
     ?>
           <div class='notice'>The <?php echo $item_given['itmname']; ?> is in progress of crafting!</div>
     <?php
           $time = time() + $r['time_to_complete'];
           $db->query("INSERT INTO `craft_inprogress` (`userid`,`item_given`,`endtime`) VALUES ({$userid}, {$r['item_given']}, {$time})");
         } else {
     ?>
           <div class='notice'>You have successfully crafted <?php echo $item_given['itmname']; ?>. You put it in your inventory!</div>
     <?php
           item_add($userid, $r['item_given'], 1);
         }
         $ex = explode(",", $r['items_needed']);
         $qty = explode(",", $r['qty_needed']);
         $n = 0;
         foreach($ex as $i) {
            item_remove($userid, $i, $qty[$n]);
            $n++;
         } 
         unset($n);
         unset($ex);
         unset($qty);
         if($r['money_needed']) { $db->query("UPDATE `users` SET `money`=`money`-{$r['money_needed']} WHERE `userid`={$userid}"); }
         if($r['coins_needed']) { $db->query("UPDATE `users` SET `coins`=`coins`-{$r['coins_needed']} WHERE `userid`={$userid}"); }
         exit($h->endpage());
     } else {
         echo "<div class='error'><strong>You cannot craft this item, for the following reasons;</strong><br />".$criteria."</div>";
         exit($h->endpage());
     }
}

Something like that?

Sorry I don't understand...But I am trying xD

Could you post the original snippet of code before these edits?

Link to comment
Share on other sites

function craft() {
global $ir, $h, $db, $userid;
   $already_crafting = $db->query("SELECT `userid`,`item_given` FROM `craft_inprogress` WHERE `userid`={$userid}");
   if($db->num_rows($already_crafting)) {
       echo "<div class='error'>You are already crafting!</div>";
       exit($h->endpage());
   }
   if(!$_GET['id']) {
       index();
       exit($h->endpage());
   }
   $_GET['id'] = filter_var($_GET['id'], FILTER_VALIDATE_INT) ? abs( (int) $_GET['id']) : 0;
   $exist = $db->query("SELECT * FROM `craft_mod` WHERE `id`={$_GET['id']}");
   if($db->num_rows($exist) == 0) {
       echo "<div class='error'>We couldn't find the blueprints for the item you wanted to craft!</div>";
       exit($h->endpage());
   }
   $r = $db->fetch_row($exist);

   if($r['donator'] AND $ir['donatordays'] == 0) {
       echo "<div class='error'>You cannot craft this item!</div>";
       exit($h->endpage());
   }

   $item_given = $db->fetch_row($db->query("SELECT `itmname` FROM `items` WHERE `itmid`={$r['item_given']}"));
   ?>
   <h3>Crafting;  <?php echo $item_given['itmname']; ?></h3>
   <?php
     $can_craft = TRUE;
     $ex = explode(",", $r['items_needed']);
     $qty = explode(",", $r['qty_needed']);
     $n = 0;
     foreach($ex as $i) {
        $get_items_needed = $db->query("SELECT `itmname` FROM `items` WHERE `itmid`={$i}");
        $t = $db->fetch_row($get_items_needed);

        $do_they_have = $db->query("SELECT `inv_itemid` FROM `inventory` WHERE `inv_userid`={$userid} AND `inv_itemid`={$i} AND `inv_qty`>={$qty[$n]}");
        if($db->num_rows($do_they_have) == 0) {
            $needs = $t['itmname']." x ". $qty[$n];
            $can_craft = FALSE;
        }
        $items_needed .= $needs .",";
        $n++;















     }
     if(isset($items_needed)) {
         $criteria = "You need the following items;<br />".$items_needed."<br />";
     }
     unset($n);

     if($r['level_needed'] > $ir['level']) { 
         $criteria .= "You need to advance in level before you can craft this item<br />";
         $can_craft = FALSE;
     }
     if($r['money_needed'] > $ir['money']) {
         $criteria .= "You need more money before you can craft this item<br />";
         $can_craft = FALSE;
     }
     if($r['coins_needed'] > $ir['coins']) {
         $criteria .= "You need more coins before you can craft this item<br />";
         $can_craft = FALSE;
     }
     if($r['minimum_days'] > $ir['daysold']) {
         $criteria .= "You need to wait ". $ir['minimum_days'] - $ir['daysold'] ." days before you can craft this item<br />";
         $can_craft = FALSE;
     }
     if($r['course_needed']) { 
         $get_course = $db->query("SELECT `name` FROM `education_courses` WHERE `ID`={$r['course_needed']}");
         $co = $db->fetch_row($get_course); 
         $have_i_completed = $db->query("SELECT `userid` FROM `education_coursesdone` WHERE `userid`={$userid} AND `courseid`={$r['course_needed']}");
         if($db->num_rows($have_i_completed) == 0) {
             $criteria .= "You need to complete the ".$co['name']." course before you can craft this item<br />";
             $can_craft = FALSE;
         }
     }

     if($can_craft) {
         if($r['time_to_complete'] > 0) {
     ?>
           <div class='notice'>The <?php echo $item_given['itmname']; ?> is in progress of crafting!</div>
     <?php
           $time = time() + $r['time_to_complete'];
           $db->query("INSERT INTO `craft_inprogress` (`userid`,`item_given`,`endtime`) VALUES ({$userid}, {$r['item_given']}, {$time})");
         } else {
     ?>
           <div class='notice'>You have successfully crafted <?php echo $item_given['itmname']; ?>. You put it in your inventory!</div>
     <?php
           item_add($userid, $r['item_given'], 1);
         }
         $ex = explode(",", $r['items_needed']);
         $qty = explode(",", $r['qty_needed']);
         $n = 0;
         foreach($ex as $i) {
            item_remove($userid, $i, $qty[$n]);
            $n++;
         } 
         unset($n);
         unset($ex);
         unset($qty);
         if($r['money_needed']) { $db->query("UPDATE `users` SET `money`=`money`-{$r['money_needed']} WHERE `userid`={$userid}"); }
         if($r['coins_needed']) { $db->query("UPDATE `users` SET `coins`=`coins`-{$r['coins_needed']} WHERE `userid`={$userid}"); }
         exit($h->endpage());
     } else {
         echo "<div class='error'><strong>You cannot craft this item, for the following reasons;</strong><br />".$criteria."</div>";
         exit($h->endpage());
     }
}
Link to comment
Share on other sites

-code snip

Try it this way:

function craft() {
global $ir, $h, $db, $userid;
   $already_crafting = $db->query("SELECT `userid`,`item_given` FROM `craft_inprogress` WHERE `userid`={$userid}");
   if($db->num_rows($already_crafting)) {
       echo "<div class='error'>You are already crafting!</div>";
       exit($h->endpage());
   }
   if(!$_GET['id']) {
       index();
       exit($h->endpage());
   }
   $_GET['id'] = filter_var($_GET['id'], FILTER_VALIDATE_INT) ? abs( (int) $_GET['id']) : 0;
   $exist = $db->query("SELECT * FROM `craft_mod` WHERE `id`={$_GET['id']}");
   if($db->num_rows($exist) == 0) {
       echo "<div class='error'>We couldn't find the blueprints for the item you wanted to craft!</div>";
       exit($h->endpage());
   }
   $r = $db->fetch_row($exist);

   if($r['donator'] AND $ir['donatordays'] == 0) {
       echo "<div class='error'>You cannot craft this item!</div>";
       exit($h->endpage());
   }

   $item_given = $db->fetch_row($db->query("SELECT `itmname` FROM `items` WHERE `itmid`={$r['item_given']}"));
   ?>
   <h3>Crafting;  <?php echo $item_given['itmname']; ?></h3>
   <?php
     $can_craft = TRUE;
     $ex = explode(",", $r['items_needed']);
     $qty = explode(",", $r['qty_needed']);
     $n = 0;

     $items_needed = '';

     foreach($ex as $i) {
        $get_items_needed = $db->query("SELECT `itmname` FROM `items` WHERE `itmid`={$i}");
        $t = $db->fetch_row($get_items_needed);

        $do_they_have = $db->query("SELECT `inv_itemid` FROM `inventory` WHERE `inv_userid`={$userid} AND `inv_itemid`={$i} AND `inv_qty`>={$qty[$n]}");
        if($db->num_rows($do_they_have) == 0) {
            $items_needed .= $t['itmname']." x ". $qty[$n].",";
            $can_craft = FALSE;
        }
        $n++;

     }
     if( trim ( $items_needed ) != '' ) {
         $criteria = "You need the following items;".$items_needed."";
     }
     unset($n);

     if($r['level_needed'] > $ir['level']) { 
         $criteria .= "You need to advance in level before you can craft this item";
         $can_craft = FALSE;
     }
     if($r['money_needed'] > $ir['money']) {
         $criteria .= "You need more money before you can craft this item";
         $can_craft = FALSE;
     }
     if($r['coins_needed'] > $ir['coins']) {
         $criteria .= "You need more coins before you can craft this item";
         $can_craft = FALSE;
     }
     if($r['minimum_days'] > $ir['daysold']) {
         $criteria .= "You need to wait ". $ir['minimum_days'] - $ir['daysold'] ." days before you can craft this item";
         $can_craft = FALSE;
     }
     if($r['course_needed']) { 
         $get_course = $db->query("SELECT `name` FROM `education_courses` WHERE `ID`={$r['course_needed']}");
         $co = $db->fetch_row($get_course); 
         $have_i_completed = $db->query("SELECT `userid` FROM `education_coursesdone` WHERE `userid`={$userid} AND `courseid`={$r['course_needed']}");
         if($db->num_rows($have_i_completed) == 0) {
             $criteria .= "You need to complete the ".$co['name']." course before you can craft this item";
             $can_craft = FALSE;
         }
     }

     if($can_craft) {
         if($r['time_to_complete'] > 0) {
     ?>
           <div class='notice'>The <?php echo $item_given['itmname']; ?> is in progress of crafting!</div>
     <?php
           $time = time() + $r['time_to_complete'];
           $db->query("INSERT INTO `craft_inprogress` (`userid`,`item_given`,`endtime`) VALUES ({$userid}, {$r['item_given']}, {$time})");
         } else {
     ?>
           <div class='notice'>You have successfully crafted <?php echo $item_given['itmname']; ?>. You put it in your inventory!</div>
     <?php
           item_add($userid, $r['item_given'], 1);
         }
         $ex = explode(",", $r['items_needed']);
         $qty = explode(",", $r['qty_needed']);
         $n = 0;
         foreach($ex as $i) {
            item_remove($userid, $i, $qty[$n]);
            $n++;
         } 
         unset($n);
         unset($ex);
         unset($qty);
         if($r['money_needed']) { $db->query("UPDATE `users` SET `money`=`money`-{$r['money_needed']} WHERE `userid`={$userid}"); }
         if($r['coins_needed']) { $db->query("UPDATE `users` SET `coins`=`coins`-{$r['coins_needed']} WHERE `userid`={$userid}"); }
         exit($h->endpage());
     } else {
         echo "<div class='error'><strong>You cannot craft this item, for the following reasons;</strong>".$criteria."</div>";
         exit($h->endpage());
     }
}
Link to comment
Share on other sites

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