andr3as Posted October 2, 2020 Share Posted October 2, 2020 i have problem with this module and i don`t understand what`s wrong with this all ?so when you buy lets say exhaust tuning its says the car its not yours or its dose's not exist. Quote Link to comment Share on other sites More sharing options...
Dayo Posted October 3, 2020 Share Posted October 3, 2020 Is “car” in your allowedMethods? Also on a side note you should look at $this->error(...); and $this->db->select(...); Quote Link to comment Share on other sites More sharing options...
ags_cs4 Posted October 3, 2020 Share Posted October 3, 2020 actualy we cant know for sure the code is not organizd try use this site with this set of options, and repost the same code again http://beautifytools.com/php-beautifier.php Quote Link to comment Share on other sites More sharing options...
Magictallguy Posted October 3, 2020 Share Posted October 3, 2020 Please copy and paste your code - a screenshot of it can make it harder to debug. On line 101, you have a variable `$garage` which does not appear to have been defined within that function or passed in via function parameters or global scoping. The code implies that it's supposed to send an error message if `$garage['GA_exhaust']` doesn't match the DB result, however, the code actually reads as setting an array key within the `$garage` var but doesn't use it. On line 112, you have another seemingly undefined variable `$value`. I've split the logics combining non-existent row with user doesn't own. What happens after trying this? (Note: Written in English. Hungarian is not a strong point of mine) public function method_exhaust() { // Get vehicle and adjoining garage data $stmt = $this->db->prepare('SELECT * FROM garage INNER JOIN cars ON CA_id = GA_car WHERE GA_id = :car '); $stmt->bindParam(':car', $this->methodData->car); $stmt->execute(); $car = $stmt->fetchObject(); if(empty($car)) { // row not found $this->alerts[] = $this->page->buildElement('error', ['text' => 'Car doesn\'t exist']); } elseif ($car->GA_uid != $this->user->id) { // row doesn't belong to user $this->alerts[] = $this->page->buildElement('error', ['text' => 'Car isn\'t yours']); } elseif ($garage['GA_exhaust'] != $this->garage->info->GA_exhaust) { // selected car part doesn't match garage entry $this->alerts[] = $this->page->buildElement('error', ['text' => 'Mismatched parts']); } elseif ($value > $this->user->info->US_money) { // Not enough money $this->alerts[] = $this->page->buildElement('error', ['text', 'Not enough money. $'.number_format($value).' required']); } else { // Make purchase // Update garage $garage = $this->db->prepare('UPDATE garage SET GA_exhaust = GA_exhaust + 100 WHERE GA_id = :id'); $garage->bindParam(':id', $car->GA_id); $garage->execute(); // Take cost $money = $this->db->prepare('UPDATE userStats SET US_money = US_money - 1000000 WHERE US_id = :id'); $money->bindParam(':id', $this->user->id); $money->execute(); // Hook it $actionHook = new hook('userAction'); $actionHook->run([ 'user' => $this->user->id, 'module' => 'tuning.exhaust', 'id' => $car->CA_id, 'success' => true, 'reward' => $value, ]); } } Quote Link to comment Share on other sites More sharing options...
Sim Posted October 3, 2020 Share Posted October 3, 2020 I would also remove your elseifs and only use ifs If(checkforErrorsLine #1) Return $this->alerts[] line If(checkforErrorsLine #2) Return $this->alerts[] line If(checkforErrorsLine #3) Return $this->alerts[] line Ect: Then just do this at end gics combining non-existent row with user doesn't own. What happens after trying this? (Note: Written in English. Hungarian is not a strong point of mine) public function method_exhaust() { // Get vehicle and adjoining garage data $stmt = $this->db->prepare('SELECT * FROM garage INNER JOIN cars ON CA_id = GA_car WHERE GA_id = :car '); $stmt->bindParam(':car', $this->methodData->car); $stmt->execute(); $car = $stmt->fetchObject(); if(empty($car)) { // row not found Return $this->alerts[] = $this->page->buildElement('error', ['text' => 'Car doesn\'t exist']); } if ($car->GA_uid != $this->user->id) { // row doesn't belong to user Return $this->alerts[] = $this->page->buildElement('error', ['text' => 'Car isn\'t yours']); } if ($garage['GA_exhaust'] != $this->garage->info->GA_exhaust) { // selected car part doesn't match garage entry Return $this->alerts[] = $this->page->buildElement('error', ['text' => 'Mismatched parts']); } If ($value > $this->user->info->US_money) { // Not enough money Return $this->alerts[] = $this->page->buildElement('error', ['text', 'Not enough money. $'.number_format($value).' required']); } // Make purchase // Update garage $garage = $this->db->prepare('UPDATE garage SET GA_exhaust = GA_exhaust + 100 WHERE GA_id = :id'); $garage->bindParam(':id', $car->GA_id); $garage->execute(); // Take cost $money = $this->db->prepare('UPDATE userStats SET US_money = US_money - 1000000 WHERE US_id = :id'); $money->bindParam(':id', $this->user->id); $money->execute(); // Hook it $actionHook = new hook('userAction'); $actionHook->run([ 'user' => $this->user->id, 'module' => 'tuning.exhaust', 'id' => $car->CA_id, 'success' => true, 'reward' => $value, ]); This is how I manage my error handling, it removes a lot of the extra bracket and leaves my logic more tabs aligned left and less nested IFs 1 Quote Link to comment Share on other sites More sharing options...
andr3as Posted October 3, 2020 Author Share Posted October 3, 2020 Thank you for everyone I sorted out the problem ☺️ And sorry was other language I forget translate back Quote Link to comment Share on other sites More sharing options...
Dayo Posted October 3, 2020 Share Posted October 3, 2020 39 minutes ago, andr3as said: Thank you for everyone I sorted out the problem ☺️ And sorry was other language I forget translate back Mind sharing what was wrong so other people know for the future? Quote Link to comment Share on other sites More sharing options...
andr3as Posted October 3, 2020 Author Share Posted October 3, 2020 Yes when I go home from work I gona post here. So I tried your solution for the tuning mode but no working Coming up one error like this, when I try to buy the exhaust for the car . Sorry something went very wrong! The error has been logged and waiting for a developer to review this issue. If you are the developer you can enable better dubuging by editing config.php and enabling debug. 10 hours ago, Magictallguy said: Please copy and paste your code - a screenshot of it can make it harder to debug. On line 101, you have a variable `$garage` which does not appear to have been defined within that function or passed in via function parameters or global scoping. The code implies that it's supposed to send an error message if `$garage['GA_exhaust']` doesn't match the DB result, however, the code actually reads as setting an array key within the `$garage` var but doesn't use it. On line 112, you have another seemingly undefined variable `$value`. I've split the logics combining non-existent row with user doesn't own. What happens after trying this? (Note: Written in English. Hungarian is not a strong point of mine) public function method_exhaust() { // Get vehicle and adjoining garage data $stmt = $this->db->prepare('SELECT * FROM garage INNER JOIN cars ON CA_id = GA_car WHERE GA_id = :car '); $stmt->bindParam(':car', $this->methodData->car); $stmt->execute(); $car = $stmt->fetchObject(); if(empty($car)) { // row not found $this->alerts[] = $this->page->buildElement('error', ['text' => 'Car doesn\'t exist']); } elseif ($car->GA_uid != $this->user->id) { // row doesn't belong to user $this->alerts[] = $this->page->buildElement('error', ['text' => 'Car isn\'t yours']); } elseif ($garage['GA_exhaust'] != $this->garage->info->GA_exhaust) { // selected car part doesn't match garage entry $this->alerts[] = $this->page->buildElement('error', ['text' => 'Mismatched parts']); } elseif ($value > $this->user->info->US_money) { // Not enough money $this->alerts[] = $this->page->buildElement('error', ['text', 'Not enough money. $'.number_format($value).' required']); } else { // Make purchase // Update garage $garage = $this->db->prepare('UPDATE garage SET GA_exhaust = GA_exhaust + 100 WHERE GA_id = :id'); $garage->bindParam(':id', $car->GA_id); $garage->execute(); // Take cost $money = $this->db->prepare('UPDATE userStats SET US_money = US_money - 1000000 WHERE US_id = :id'); $money->bindParam(':id', $this->user->id); $money->execute(); // Hook it $actionHook = new hook('userAction'); $actionHook->run([ 'user' => $this->user->id, 'module' => 'tuning.exhaust', 'id' => $car->CA_id, 'success' => true, 'reward' => $value, ]); } } public function method_exhaust() { // Get vehicle and adjoining garage data $stmt = $this->db->prepare('SELECT * FROM garage INNER JOIN cars ON CA_id = GA_car WHERE GA_id = :car '); $stmt->bindParam(':car', $this->methodData->car); $stmt->execute(); $car = $stmt->fetchObject(); if(empty($car)) { // row not found $this->alerts[] = $this->page->buildElement('error', ['text' => 'Car doesn\'t exist']); } elseif ($car->GA_uid != $this->user->id) { // row doesn't belong to user $this->alerts[] = $this->page->buildElement('error', ['text' => 'Car isn\'t yours']); } elseif ($garage['GA_exhaust'] != $this->garage->info->GA_exhaust) { // selected car part doesn't match garage entry $this->alerts[] = $this->page->buildElement('error', ['text' => 'Mismatched parts']); } elseif ($value > $this->user->info->US_money) { // Not enough money $this->alerts[] = $this->page->buildElement('error', ['text', 'Not enough money. $'.number_format($value).' required']); } else { // Make purchase // Update garage $garage = $this->db->prepare('UPDATE garage SET GA_exhaust = GA_exhaust + 100 WHERE GA_id = :id'); $garage->bindParam(':id', $car->GA_id); $garage->execute(); // Take cost $money = $this->db->prepare('UPDATE userStats SET US_money = US_money - 1000000 WHERE US_id = :id'); $money->bindParam(':id', $this->user->id); $money->execute(); // Hook it $actionHook = new hook('userAction'); $actionHook->run([ 'user' => $this->user->id, 'module' => 'tuning.exhaust', 'id' => $car->CA_id, 'success' => true, 'reward' => $value, ]); } } Sim I try your solution as well but also no working. 9 hours ago, Sim said: I would also remove your elseifs and only use ifs If(checkforErrorsLine #1) Return $this->alerts[] line If(checkforErrorsLine #2) Return $this->alerts[] line If(checkforErrorsLine #3) Return $this->alerts[] line Ect: Then just do this at end gics combining non-existent row with user doesn't own. What happens after trying this? (Note: Written in English. Hungarian is not a strong point of mine) public function method_exhaust() { // Get vehicle and adjoining garage data $stmt = $this->db->prepare('SELECT * FROM garage INNER JOIN cars ON CA_id = GA_car WHERE GA_id = :car '); $stmt->bindParam(':car', $this->methodData->car); $stmt->execute(); $car = $stmt->fetchObject(); if(empty($car)) { // row not found Return $this->alerts[] = $this->page->buildElement('error', ['text' => 'Car doesn\'t exist']); } if ($car->GA_uid != $this->user->id) { // row doesn't belong to user Return $this->alerts[] = $this->page->buildElement('error', ['text' => 'Car isn\'t yours']); } if ($garage['GA_exhaust'] != $this->garage->info->GA_exhaust) { // selected car part doesn't match garage entry Return $this->alerts[] = $this->page->buildElement('error', ['text' => 'Mismatched parts']); } If ($value > $this->user->info->US_money) { // Not enough money Return $this->alerts[] = $this->page->buildElement('error', ['text', 'Not enough money. $'.number_format($value).' required']); } // Make purchase // Update garage $garage = $this->db->prepare('UPDATE garage SET GA_exhaust = GA_exhaust + 100 WHERE GA_id = :id'); $garage->bindParam(':id', $car->GA_id); $garage->execute(); // Take cost $money = $this->db->prepare('UPDATE userStats SET US_money = US_money - 1000000 WHERE US_id = :id'); $money->bindParam(':id', $this->user->id); $money->execute(); // Hook it $actionHook = new hook('userAction'); $actionHook->run([ 'user' => $this->user->id, 'module' => 'tuning.exhaust', 'id' => $car->CA_id, 'success' => true, 'reward' => $value, ]); This is how I manage my error handling, it removes a lot of the extra bracket and leaves my logic more tabs aligned left and less nested IFs Sorry something went very wrong! The error has been logged and waiting for a developer to review this issue. If you are the developer you can enable better dubuging by editing config.php and enabling debug With this solution working now for me. I know its not the best solution.Now I just need to add to don't let peoples to buy more than 1 tuning part for each car. public function method_exhaust() { $car = $this->db->prepare("SELECT * FROM garage INNER JOIN cars ON (CA_id = GA_car) WHERE GA_id = :car"); $car->bindParam(':car', $this->methodData->car); $car->execute(); $car = $car->fetchObject(); if (empty($car) || $car->GA_uid != $this->user->id) { $this->alerts[] = $this->page->buildElement('error', array("text"=>'Car doesnt exist')); } else if ($this->user->info->US_money <= 0) { $this->alerts[] = $this->page->buildElement('error', array("text" => "Not enough money!")); } else if ($this->garage->info->GA_exhaust == 100) { $this->alerts[] = $this->page->buildElement('error', array("text" => "You all ready have this")); } else { if ($value < $this->user->info->US_money) { $this->alerts[] = $this->page->buildElement('success', array("text"=>'You buyed exhaust tuning.')); $this->db->query("UPDATE garage SET GA_exhaust = GA_exhaust + 100 WHERE GA_id = ".$car->GA_id); $this->db->query("UPDATE userStats SET US_money = US_money - 1000000 WHERE US_id = ".$this->user->id); $actionHook = new hook("userAction"); $action = array( "user" => $this->user->id, "module" => "tuning.exhaust", "id" => $car->CA_id, "success" => true, "reward" => $value ); $actionHook->run($action); } } } Quote Link to comment Share on other sites More sharing options...
Sim Posted October 4, 2020 Share Posted October 4, 2020 I was not trying to give a solution but show you something regarding your nested error handling 1 Quote Link to comment Share on other sites More sharing options...
andr3as Posted October 4, 2020 Author Share Posted October 4, 2020 53 minutes ago, Sim said: I was not trying to give a solution but show you something regarding your nested error handling Thanks I gonna check better when I have time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.