dean7 Posted November 9, 2016 Share Posted November 9, 2016 Hey guys I've got this script which I've been coding which allows users to stock cars.. I've been testing it as I code it in which all the error messages display at the right time work on hitting submit but when it comes to the time to update the database it just refreshes the page and don't do anything. I cannot work out the reason why? elseif (is_numeric($BuyCars)){ // Form has value, form is ALSO a number // Now get cost of the car to stock and how many they want // $Stocked is CarName $CarInfo = $db->prepare("SELECT * FROM `cars` WHERE carname = :carname"); $CarInfo->bindParam(":carname", $Stocked); $CarInfo->execute(); $CarReal = $CarInfo->rowCount(); $GetTheStockNow = $db->prepare("SELECT * FROM `Dealercars` WHERE location = :location AND carname = :carname"); $GetTheStockNow->bindParam(":location", $DeLoc); $GetTheStockNow->bindParam(":carname", $Stocked); $GetTheStockNow->execute(); $GetTheThe = $GetTheStockNow->fetchObject(); if ($CarReal != "1"){ echo "Failed finding car"; }elseif ($CarReal >= "1"){ // Car Found $OldCarStats = $CarInfo->fetchObject(); $BuyPrice = $OldCarStats->value; // Value of Car from defult value $CostOfBuy = $BuyPrice * $BuyCars; // Cost of stock $Money = $UsersTable1->money; // $Usernames money // Has the $Username got enough money to buy the stock? if ($UsersTable1->money < $CostOfBuy){ echo "You dont have enough money to buy this amount of stock!"; }elseif ($UsersTable1->money >= $CostOfBuy){ $StuffStock = $GetTheThe->stock; $NewMoney = $Money - $CostOfBuy; // Money after buying stock $NewStock = $StuffStock + $BuyCars; // The New Stock // Take the money from user for buying stock $TakeMoneyAway = $db->prepare("UPDATE `UsersRegTable` SET money = :money WHERE username = :username"); $TakeMoneyAway->bindValue(':money', $NewMoney); $TakeMoneyAway->bindValue(':username', $Username); $TakeMoneyAway->execute(); // Update thier car dealership with the stock they just brought $UpdateStock = $db->prepare("UPDATE `Dealercars` SET stock = :stock WHERE location = :location AND carname = :carname"); $UpdateStock->bindValue(':stock', $NewStock); $UpdateStock->bindValue(':carname', $Stocked); $UpdateStock->bindValue(':location', $DeLoc); $UpdateStock->execute(); echo "You successfully brought ".htmlspecialchars(number_format($BuyCars))." for £ ".htmlspecialchars(number_format($CostOfBuy)).""; } Am I missing something very obvious here ? Thanks for any help given Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 9, 2016 Share Posted November 9, 2016 what debugging have you done to find out WHAT the code IS doing? do you have php's error_reporting set to E_ALL and display_errors set to ON (in the php.ini on your development system) so that php would help you by reporting and displaying all the errors it detects? are you sure the elseif() statement being shown is true and that no prior related if() or elseif() statement was true so that the shown elseif() will even be executed? do you have the PDO error mode set to exceptions so that database errors will throw an exception, combined with the suggested php error_reporting/display_errors settings, so you will see any database errors? is there a header() redirect later in the code that could be redirecting back to the same page, combined with php's output_buffering being on, that would hide any php errors or any output from echo statements in your code? Quote Link to comment Share on other sites More sharing options...
dean7 Posted November 9, 2016 Author Share Posted November 9, 2016 I've just been re looking to find that I missed placed a }. After reading what Mac_gyver said about the if() elseif() made me see it ! Thanks 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.