Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sultanwebdev's avatar

SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'neviforce' for column 'product_subcategory_id' at row 1 (Connection: mysql, SQL: insert into

anyone help me this SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'neviforce' for column 'product_subcategory_id' at row 1 (Connection: mysql, SQL: insert into products (product_name, product_short_des, product_long_des, price, discount_price, product_quantity, product_category_name, product_subcategory_name, product_category_id, product_subcategory_id, product_image, product_slug) values (iphone 13 pro max, sddsdsfdsf, zvcxvxcvxv, 500, 450, 5, Watches, ?, 23, neviforce, upload/1760551628853092.png, ))

controller code is

public function StoreProduct(Request $request) {

     $image = $request->file('product_image');
     $image_name = hexdec(uniqid()).'.'.$image->getClientOriginalExtension();
     $request->product_image->move(public_path('/upload').$image_name);
     $img_url = 'upload/'.$image_name;

    $category_id = $request->product_category_id;
    $subcategory_id = $request->product_subcategory_id;

    $category_name = Category::where('id', $category_id)->value('category_name');
    $subcategory_name = Subcategory::where('id', $subcategory_id)->value('subcategory_name');

         Product::insert([
            'product_name' => $request->product_name,
            'product_short_des' => $request->product_short_des,
            'product_long_des' => $request->product_long_des,
            'price' => $request->price,
            'discount_price' => $request->discount_price,
            'product_quantity' => $request->product_quantity,
            'product_category_name' => $category_name,
            'product_subcategory_name' => $subcategory_name,
            'product_category_id' => $request->product_category_id,
            'product_subcategory_id' => $request->product_subcategory_id,
            'product_image' => $img_url,
            'product_slug' =>  Strtolower(str_replace(' ', '-', $request->product_slug))

        ]);

        Category::where('id', $category_id)->increment('product_count', 1);
        Subcategory::where('id', $category_id)->increment('product_count', 1);

        $notification = array(
            'message' => 'Product Added Successfully',
            'alert-type' => 'info'
        );

        return redirect()->route('all.product')->with($notification);

blade code is :

Page/ Add Product

Add New Product
@csrf Product Name
                        <div class="row mb-3">
                            <label class="col-sm-2 col-form-label" for="basic-default-name">Product
                                Price</label>
                            <div class="col-sm-10">
                                <input type="text" name="price" class="form-control" id="price"
                                    placeholder="Product price" />
                            </div>
                        </div>

                        <div class="row mb-3">
                            <label class="col-sm-2 col-form-label" for="basic-default-name">Discount Price
                                Price</label>
                            <div class="col-sm-10">
                                <input type="text" name="discount_price" class="form-control" id="discount_price"
                                    placeholder="DISCOUNT PRICE PRICE" />
                            </div>
                        </div>
                        <div class="row mb-3">
                            <label class="col-sm-2 col-form-label" for="basic-default-name">Product
                                Quantity</label>
                            <div class="col-sm-10">
                                <input type="text" name="product_quantity" class="form-control" id="product_quantity"
                                    placeholder="Product Quantity" />
                            </div>
                        </div>
                        <div class="row mb-3">
                            <label class="col-sm-2 col-form-label" for="basic-default-name">short Description</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" name="product_short_des" id="product_short_des" rows="3"></textarea>
                            </div>
                        </div>
                        <div class="row mb-3">
                            <label class="col-sm-2 col-form-label" for="basic-default-name">Long Description</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" name="product_long_des" id="product_long_des" rows="3"></textarea>
                            </div>
                        </div>
                        <div class="row mb-3">
                            <label class="col-sm-2 col-form-label" for="basic-default-name">Select category
                            </label>
                            <div class="col-sm-10">
                                <select class="form-select" name="product_category_id" id="product_category_id"
                                    aria-label="Default select example">
                                    <option selected> select Category</option>
                                    @foreach ($category as $item)
                                        <option value="{{ $item->id }}">{{ $item->category_name }}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="row mb-3">
                            <label class="col-sm-2 col-form-label" for="basic-default-name">Select subcategory
                            </label>
                            <div class="col-sm-10">
                                <select class="form-select" name="product_subcategory_id" id="product_subcategory_id"
                                    aria-label="Default select example">
                                    <option selected> select subCategory</option>
                                    @foreach ($subcategory as $item)
                                        <option value="{{ $item->subcategory_name }}">{{ $item->subcategory_name }}
                                        </option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="row mb-3">
                            <label class="col-sm-2 col-form-label" for="basic-default-name">Product
                                Image</label>
                            <div class="col-sm-10">
                                <input class="form-control" type="file" name="product_image" id="product_image">
                            </div>
                        </div>

                </div>
                <div class="row justify-content-end">
                    <div class="col-sm-10">
                        <button type="submit" class="btn btn-primary">Add Product</button>
                    </div>
                </div>
                </form>
            </div>
        </div>
    </div>
</div>
0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

The error message indicates that the value being inserted into the product_subcategory_id column is not an integer. Looking at the code, it seems that the value being passed is the product_subcategory_name instead of the product_subcategory_id.

To fix this, we need to update the blade code to pass the product_subcategory_id instead of the product_subcategory_name. We can do this by updating the value of the option tag in the subcategory select dropdown to be the id instead of the subcategory_name.

Here's the updated blade code:

<div class="row mb-3">
    <label class="col-sm-2 col-form-label" for="basic-default-name">Select subcategory</label>
    <div class="col-sm-10">
        <select class="form-select" name="product_subcategory_id" id="product_subcategory_id" aria-label="Default select example">
            <option selected> select subCategory</option>
            @foreach ($subcategory as $item)
                <option value="{{ $item->id }}">{{ $item->subcategory_name }}</option>
            @endforeach
        </select>
    </div>
</div>

With this change, the product_subcategory_id should now be passed as an integer to the controller, and the error should be resolved.

Please or to participate in this conversation.