Empty values being added to all mysql rows instead of just the target row

后端 未结 2 1981
不知归路
不知归路 2021-01-28 13:47

Empty columns are being added to my MySQL rows upon submitting data into my server. I am entering it into one row but all rows get at least an empty column. How can I prevent th

2条回答
  •  清酒与你
    2021-01-28 14:30

    Have you attempted to print out the contents of category to the console? Is it possible that a valid category and a null category is being posted back from the source?

    you could also try encapulating the sql call with a nul check against the category. This might catch the null before its inserted.

    $category = $_POST['category'];
    $cf = $_FILES['cf'];
    
    if($category != NULL)
    {
        mysqli_query($conn, "INSERT INTO adDatabase(".$category.") VALUES(8)");
    }
    

    Lastly you could set one of the columns in the table to not allow null values. Which would allow you to put a try catch block and dispose of the empty data

    Try {
        mysqli_query($conn, "INSERT INTO adDatabase(".$category.") VALUES(8)");
    } 
    catch (exception ex)
    {
        // do nothing!
    }
    

提交回复
热议问题