JanOve's avatar

A non well formed numeric value encountered

Hi, I'm on to build a ecommerce with laravel 7. But now I'm stuck with this error: A non well formed numeric value encountered. I have searched for a solution online but I can not find any help. My course leader can not answer that either.

In the top of the file I has this lines of code.

@php $featured = DB::table('products')->where('status',1)->orderBy('id','desc')->limit(12)->get();

$trend = DB::table('products')->where('status',1)->where('trend',1)->orderBy('id','desc')->limit(8)->get();

$best = DB::table('products')->where('status',1)->where('best_rated',1)->orderBy('id','desc')->limit(8)->get();

@endphp

                  <div class="product_extras">

                        <div class="product_color">

                            <input type="radio" checked name="product_color" style="background:#b19c83">

                            <input type="radio" name="product_color" style="background:#000000">

                            <input type="radio" name="product_color" style="background:#999999">

                        </div>

                        <button class="product_cart_button">Lägg i kundvagnen</button>

                    </div>

                </div>

                <div class="product_fav"><i class="fas fa-heart"></i></div>

                <ul class="product_marks">


                    @if($row->discount_price == NULL)

                    <li class="product_mark product_discount" style="background: blue;">Ny</li>

                    @else

                    <li class='product_mark product_discount'> 😢 This line is marked as an error

                    @php

                        $amount=$row->selling_price - $row->discount_price;

                        $discount=$amount/$row->selling_price*100;

                    @endphp


                    {{ intval($discount) }}



                    </li>

                    @endif



               </ul>

            </div>

        </div>

I'm a beginner, you could say. Have taken a few courses, but I do not solve this problem.

Best regards JanOve

0 likes
11 replies
JanOve's avatar

Thank you for the answer, but I have done "composer update", but the error is still there.

Snapey's avatar

is it this line?

 $discount=$amount/$row->selling_price*100;

(it helps a lot if you say which line is the problem)

So your selling_price is possibly not a number. You also have the potential here to create a divide by zero error if the selling price happens to be zero.

1 like
JanOve's avatar

Hi, I have marked the line with text and a smiley. The line is this:

  • Thanks for your reply.

  • JanOve's avatar
    JanOve
    OP
    Best Answer
    Level 1

    The line disappeared.

    This is the line:

    product_mark product_discount

    Snapey's avatar

    that line is just css class names and cannot cause any php errors. What is the full error message?

    Or have you fixed this since you already marked best answer?

    JanOve's avatar

    The error has not been corrected. I clicked in the wrong place. Now I understand even less, because now I get a message that says: ParseError syntax error, unexpected end of file Can I post the whole page, where the error is?

    jlrdw's avatar

    Are you using an IDE editor to help track down code errors?

    If not, only do part of the code, see if error, add more code, check for error, etc.

    JanOve's avatar

    When I deactivate all products, it works. What can I do? Grateful for all the help I can get.

    Snapey's avatar

    what can I do?

    share your code.

    If you have unexpected end of file it means that you have an imbalance of opening and closing blade tags or php statements (which don't really belong in the view)

    Please or to participate in this conversation.