-1

A non-numeric value encountered

on line number 51 means this line it show me an error non-numeric value

->update('purchase',array('item_qty'=>'item_qty'+$item_qty));

function upd_sales($upd_sales)
{
    $item_name=$upd_sales['item_name'];
    $item_qty=$upd_sales['item_qty'];
         $this->db
                ->where('item_code', $item_name)
               ->update('purchase',array('item_qty'=>'item_qty'+$item_qty));
}
Pradeep
  • 9,667
  • 13
  • 27
  • 34

5 Answers5

0

This isn't javascript

array('item_qty'=>'item_qty'+$item_qty)

If your trying to concant with the + that is. Otherwise it doesn't make much sense to add strings. Maybe you wanted this instead

array('item_qty'=>'item_qty'.$item_qty)

With a Dot .

Or maybe you just need the value of it.

array('item_qty'=>$item_qty)

Which is more likely because PHP don't care about the variable type, but the database might and your error says NON-Numeric so concat will always give you a string which is non-numeric in its type.

ArtisticPhoenix
  • 21,464
  • 2
  • 24
  • 38
0

You are doing string + numeric instead of math operation

exactly on this line ->update('purchase',array('item_qty'=>'item_qty'+$item_qty));

    function upd_sales($upd_sales)
    {
        $item_name=$upd_sales['item_name'];
        $item_qty=$upd_sales['item_qty'];
             $this->db


        ->where('item_code', $item_name)
               ->update('purchase',array('item_qty'=>$item_qty));
}
Ray A
  • 1,283
  • 2
  • 10
  • 22
  • `'item_qty'+$item_qty` is not string concatenation, well not in PHP at lest, that's fine if its JavaScript As PHP we use the dot `.` not the `+`. What they have is adding a string to a variable, which PHP is probably fine with, but makes no sense logically as it will be seeing the sting as `0` + the number. – ArtisticPhoenix Aug 13 '18 at 10:49
0
function upd_sales($upd_sales)
{
    $item_name=$upd_sales['item_name'];
    $item_qty=$upd_sales['item_qty'];
         $this->db
                ->where('item_code', $item_name)
                ->update('purchase',array('item_qty'=>'item_qty'+$item_qty)); //'item_qty is string where as $item_qty in number
}

That is because you are trying to get sum of string and number.

Change your code to

function upd_sales($upd_sales)
{
    $item_name=$upd_sales['item_name'];
    $item_qty=$upd_sales['item_qty'];
         $this->db
                ->where('item_code', $item_name)
                ->update('purchase',array('item_qty'=> $item_qty));
}
0

Try out this way, you need to write a way in mysql update item quantity

function upd_sales($upd_sales)
{
    $item_name=$upd_sales['item_name'];
    $item_qty=$upd_sales['item_qty'];
    $this->db->where('item_code', $item_name)
       ->set('item_qty', 'item_qty+'.$item_qty, FALSE);
       ->update('purchase');
}
Yogesh Salvi
  • 1,177
  • 2
  • 10
  • 17
0

case $competitor1 : // competitor 1 wins $result = $resultwin1;

            $won1 = get_post_meta($competitor1, 'won', true);
            update_post_meta($competitor1, 'won', $won1 + 1);
            wps_update_history ( $competitor1, 'won', '', $lastIP );
            update_post_meta($competitor1, 'lasttimestampbattle', current_time( "timestamp" ) );

            $lost2 = get_post_meta($competitor2, 'lost', true);
            update_post_meta($competitor2, 'lost', $lost2 + 1);
            wps_update_history ( $competitor2, 'lost', '', $lastIP );

            if ($haswon != "") {
              // get actual post title
              $postdata = get_post($competitor1);
              if ( strlen ( $postdata->post_title ) > 0 )
                $result = $postdata->post_title . " " . $haswon;
            }
            break;