Danny620 Posted August 4, 2009 Share Posted August 4, 2009 right what this code should do is first run and check to see if it has got the right amont of each item and the if it has it should store 1 in a var of $passed which then gets passed to my other function then if $passed has 1 in then it would run and update the db but when i click the buttion nothing happes heres the code <?php //require connection $dbc require_once ('mysqli_connect.php'); function stuff($cost,$dbc){ //function stuff() needs $cost,$dbc //Gets how much the user has of that stuff already //selects table stuff and querys for item,item_x,item_y // Query the database: $q = "SELECT item, item_x, item_y FROM `stuff` WHERE user_id = 1"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); $stuff = mysqli_fetch_array ($r, MYSQLI_ASSOC); //End of Hq level //fetch's an array and then puts the item's in vars $item = $stuff['item']; $item_x = $stuff['item_x']; $item_y = $stuff['item_y']; //Get's the users corrent level of the building they wish to update $q = "SELECT level FROM `buildings` WHERE user_id = 1 & building = '$cost'"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); $level = mysqli_fetch_array ($r, MYSQLI_ASSOC); $buildinglevel = $level['level']; //testing zone echo "item: $item<br />item_x: $item_x<br />item_y: $item_y<br />"; //end of testing zone //querys the dbc for how much it will cost the user to upgrade there building // Query the database: $q = "SELECT item, item_x, item_y FROM `$cost` WHERE level = '$buildinglevel'"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); $buidlingstuff = mysqli_fetch_array ($r, MYSQLI_ASSOC); //End of Hq level //Starts an array and stores the cost of each item it will cost to upgrade $costitem = $buidlingstuff['item']; $costitem_x = $buidlingstuff['item_x']; $costitem_y = $buidlingstuff['item_y']; echo "<br />costitem: $costitem<br />costitem_x: $costitem_x<br />costitem_y: $costitem_y"; // Assume invalid values: $im = $imx = $imy = FALSE; //item if($item >= $costitem){ $im = 1; }else{ echo "Not enough"; } if($item_x >= $costitem_x){ $imx = 1; }else{ echo "Not enough"; } if($item_y >= $costitem_y){ $imy = 1; }else{ echo "Not enough"; } if($im && $imx && $imy){ $passed = 1; }else{ $passed = 0; } } function levelup($dbc,$cost,$passed){ //New function called levelup needs $dbc and $cost //Get HQ level. // Query the database: $q = "SELECT level, points FROM `buildings` WHERE user_id = 1 & building = '$updatebuilding'"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); $nowhqlevel = mysqli_fetch_array ($r, MYSQLI_ASSOC); //End of Hq level $hqlevel = $nowhqlevel['level']; $pointsnow = $nowhqlevel['points']; //Get HQ Buildtime. // Query the database: $q = "SELECT time, points FROM `hq` WHERE level = $hqlevel"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); $nowbuildtime = mysqli_fetch_array ($r, MYSQLI_ASSOC); //End HQ Buildtime. $points = $nowbuildtime['points']; $buildtime = $nowbuildtime['time']; $builddate = date("Y-m-d H:i:s", time() + (60 * $buildtime)); $userid = 1;//turn it to session when programmed login //Upgrade to the next level. if(isset($_POST['update'])){ if($passed){ echo $passed; // Query the database: $q = "UPDATE construction SET complete = '$builddate', progress = 1 WHERE user_id = $userid LIMIT 1"; $r = @mysqli_query ($dbc, $q); } else { } } //Check to see if any buildings are in progress $q = "SELECT progress, complete FROM `construction` WHERE user_id = $userid & progress = 1"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); $progress = mysqli_fetch_array ($r, MYSQLI_ASSOC); //Settings $buildingpro = '0'; if($progress['progress'] == 1){ $msg = "You have 1 building in construction it will be finshished on " .$progress['complete']; //Check if building is complete $q = "SELECT complete FROM `construction` WHERE user_id = $userid & progress = 1"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); $check = mysqli_fetch_array ($r, MYSQLI_ASSOC); $date = date("Y-m-d H:i:s"); if($date >= $check['complete']){ $q = "UPDATE construction SET progress = 0 WHERE user_id = $userid & progress = 1 LIMIT 1"; $r = @mysqli_query ($dbc, $q); $upgraded = ++$hqlevel; $addpoints = $pointsnow + $points; echo $addpoints; $q = "UPDATE buildings SET level = '$upgraded', points = '$addpoints' WHERE user_id = $userid & building = 'hq' LIMIT 1"; $r = @mysqli_query ($dbc, $q); $msg = "Building is Complete"; }else{ $buildingpro = "<b>Building in progress</b>"; } } } stuff(hq,$dbc); levelup($dbc,$cost,$passed); ?> Link to comment https://forums.phpfreaks.com/topic/168854-no-errors-but-no-update/ Share on other sites More sharing options...
ToonMariner Posted August 4, 2009 Share Posted August 4, 2009 $r = mysqli_query ($dbc, $q) should be $r = mysqli_query ($q, $dbc) Link to comment https://forums.phpfreaks.com/topic/168854-no-errors-but-no-update/#findComment-890914 Share on other sites More sharing options...
Danny620 Posted August 4, 2009 Author Share Posted August 4, 2009 no it should'tn m8 because i had it working before when i did other tests so its not that Link to comment https://forums.phpfreaks.com/topic/168854-no-errors-but-no-update/#findComment-890920 Share on other sites More sharing options...
Bjom Posted August 4, 2009 Share Posted August 4, 2009 Do you get your $msg = "Building is Complete";? I.e: is the query reached and malfunctions, or does your code never get there? If it is not reached, I would suggest you insert a echo 'passed this an that if-statement'; after each if, so you can find out where your code branches away... P.S.: Your trigger_error only triggers a E_USER_NOTIFICATION, after which the code continues, is that intentional? if not try adding a second parameter like so: trigger_error('msg', E_USER_ERROR), which will interrupt the code. Link to comment https://forums.phpfreaks.com/topic/168854-no-errors-but-no-update/#findComment-890959 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.