Jump to content

Unsupported Operand Types


Silvar

Recommended Posts

Hello everyone.

This seems to be a nice forum! You will be seeing me here a lot in the future.

Anyway, I got a problem with this code:

 

$editId = $_GET["edit"];
$getCurrentAmount = mysql_query("SELECT amount FROM guilt_list WHERE id = $editId") or die(mysql_error());
$amountIsCurrently = mysql_fetch_row($getCurrentAmount);
$listAmount = $amountIsCurrently+$gAmount;

mysql_query("UPDATE guilt_list SET name='$gName', amount='$listAmount' WHERE id='$editId'");

 

It gives me: "Fatal error: Unsupported operand types in /var/www/********/public_html/guilt.php on line 171"

 

Line 171 is:

$listAmount = $amountIsCurrently+$gAmount;

 

What seems to be the problem? I can't figure it out.

Thanks in advance and happy new year!

 

Best regards,

- Silvar

Link to comment
https://forums.phpfreaks.com/topic/272554-unsupported-operand-types/
Share on other sites

I don't know about $gAmount but $amountIsCurrently is an array. You have to go into it to grab the "amount" you selected in the query.

If you aren't sure of the structure of the array, print_r() or var_dump() it.

 

[edit] It would be a lot easier for you to add the $gAmount in a single query. Don't have to get PHP involved in any of that.

UPDATE guilt_list SET name = '$gName', amount = amount + $gAmount WHERE id = $editId

I don't know about $gAmount but $amountIsCurrently is an array. You have to go into it to grab the "amount" you selected in the query.

If you aren't sure of the structure of the array, print_r() or var_dump() it.

 

[edit] It would be a lot easier for you to add the $gAmount in a single query. Don't have to get PHP involved in any of that.

UPDATE guilt_list SET name = '$gName', amount = amount + $gAmount WHERE id = $editId

 

So how would you rewrite this code to do the proper action:


$gName = htmlspecialchars(addslashes($_POST["editName"]));
$gAmount = $_POST["editAmount"];
$gDate = date("d/m-Y");

if(!empty($gName) && !empty($gAmount)) {
$editId = $_GET["edit"];
$getCurrentAmount = mysql_query("SELECT amount FROM guilt_list WHERE id = $editId") or die(mysql_error());
$amountIsCurrently = mysql_fetch_row($getCurrentAmount);
$listAmount = $amountIsCurrently+$gAmount;

mysql_query("UPDATE guilt_list SET name='$gName', amount='$listAmount' WHERE id='$editId'");

mysql_query("INSERT INTO guilt_changes(id, amount, date) VALUES('$editId', '$gAmount', '$gDate')") or die(mysql_error());
echo "<h2>Success: The guilt that ".$gName." owes has been edited!</h2>";
echo "<div style=\"width: 680px; margin: 10px 0 10px 0\"> </div>";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.