So ns am pretty new to PHP and the publication that ns learned that from seems to have actually taught it a small funny, however I am functioning on an update for the horse video game I am creating. That is in php making use of mysql together a database. Here is the code:


You are watching: Call to a member function fetch_assoc() on a non-object

$today=date("Y-m-d");$sql="SELECT*FROMupgrades";$result=mysqli_query($cxn,$sql)ordie("couldn"texecutequery.");while($row=$result->fetch_assoc()){extract($row);echo"

$username$upgradetype

";$sql="SELECT*frombankwhereuser="$username"";$result2=mysqli_query($cxn,$sql)ordie("couldn"texecutequery.");$row2=$result2->fetch_assoc();extract($row2);echo"

$balance

";If($upgradetype=="free")$newbalance=$balance+1000;$transaction=1000;Elseif($upgradetype=="bronze")$newbalance=$balance+2000;$transaction=2000;Elseif($upgradetype=="silver")$newbalance=$balance+4000;$transaction=4000;Elseif($upgradetype=="gold")$newbalance=$balance+6000;$transaction=6000;echo"$newbalance$transaction";?>
This works well, i don"t have any kind of problems with it. I am trial and error two accounts ideal now and it will echo the usernames and also balances and also transaction amounts, however once I add the following (I did add it before the ?> line):
$query="UPDATEbanksetbalance="$newbalance"whereuser="$username"";$result=mysqli_query($cxn,$query)ordie("couldn"texecutequery.");$query="INSERTintotransactions(username,othername,transactionamount,transactiontype,transactiondate,transactionmemo)values("$username","Staff","$transaction","Deposit","$today","Salary")";$result=mysqli_query($cxn,$query)ordie("Couldn"texecutequery.");
I acquire the following:Fatal error: speak to to a member function fetch_assoc() on a non-object in C:AppServwwwupdatesalary.php on heat 12Line 12 is the if statement for the first query. I am not certain what is not correct here. Any kind of ideas?
Reply with Quote
Junior Member
If this has operated before, shot 1) do var_dump($result) on line 12(after while) if it is not mysql_result(false) shot mysql_error() or something favor it. 2) Visit database and also make that user through this username existsbut i think trouble in $row = $result->fetch_assoc(), because you use mysql attributes ( not mysqli course ) and it not object. Shot mysql_fetch_assoc($result);http://www.php.net/manual/en/functio...etch-assoc.php
Reply with Quote
Junior Member
seca83 is correct. You space not utilizing fetch_assoc correctly due to the fact that $result is not an item ( choose a class object ) and also you room treating it together one prior to it actually becomes one.
Reply with Quote
ok, so ns was said in another forum to change that line to $row2=$result2->fetch_assoc(); because originally ns was getting this error:Warning: mysqli_fetch_assoc() expects parameter 1 to it is in mysqli_result, boolean offered in C:AppServwwwupdatesalary.php on heat 12Changing that took that error away and also then gave me the one above. What do I perform now? i am now getting the error simply mentioned. Many thanks for your help btw.
O and this is what I acquire when I add var_dump($result); after ~ the when statement:object(mysqli_result)#2 (0) if the helps
Quick NavigationScripting - Server side (PHP, Perl, etc.)TopSite Areaskatifund.orgVisual C++ & C++ ProgrammingC# ProgrammingVisual simple ProgrammingWindows 8 and Later keep DevelopmentOther .NET Programming.NET FrameworkJava ProgrammingOther ProgrammingGeneral Discussionkatifund.org CommunityProgramming ProjectsSlow conversation ArchivesJobskatifund.org technical FAQsRetired Forum Areas
You may not post new threadsYou may not article repliesYou may not post attachmentsYou may not modify your posts
* The finest Reasons come Target windows 8
Learn some of the best reasons why you must seriously consider bringing your Android mobile advancement expertise come bear top top the windows 8 platform.


See more: Puneet Kaur Uc Berkeley - Mcmaster Medicine And Health Society

terms of organization | about Us | Privacy an alert | contact Us | advertisement |Sitemap| California - perform Not sell My details

Advertiser Disclosure: few of the products that appear on this site are from carriers from which TechnologyAdvice obtain compensation. This compensation may impact how and also where products appear on this website including, for example, the bespeak in which they appear. TechnologyAdvice go not encompass all providers or all varieties of products easily accessible in the marketplace.