• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object of class mysqli_result could not be converted to string/int

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my table ,i have a field called base_pay with type int(11).

When i retrieve the base_pay of a employee and try to add or multiply the base_pay.
Here are my queries


$result = mysqli_query($con,"SELECT base_pay FROM guest where name='Mahtab'");
mysqli_query($con,"UPDATE guest SET net_pay='$result*15"
WHERE name='Mahtab'");

It says Catchable fatal error: Object of class mysqli_result could not be converted to string

Does it mean that the return type of query is not int.

If not then how to do some mathematics on an int field retrieved from table.

 
Nick Charles
Ranch Hand
Posts: 71
Linux PHP Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is correct, a mysql_result cannot be converted into an integer; instead a mysql_result is a handle for a collection of data that you have to get a row at a time. So what you need to do is extract the integer from the mysql_result, like this:

$row = mysql_fetch_row($result);
$base_pay = $row[0];

There are other ways to do this also. Try looking up a PHP with MySQL turorial.
 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You , I get it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic