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

Edited by Silvar
Link to comment
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

Edited by requinix
Link to comment
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

 

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>";
}

Edited by Silvar
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.