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
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!
}