I’d wrap $update with single quotes (notice that I flipped the quotations) and changed id1 into $id1:
mysqli_query($conn , "update insert1 set ".$name." = '".$update."'
where id-1 = ".$id1 );
If id-1 is a string column type in the database then I’d wrap $id1 with single quotes. like this:
mysqli_query($conn , "update insert1 set ".$name." = '".$update."'
where id-1 = '".$id1."'" );
Notes:
- I’d double check if
id-1is intended in theWHEREcondition, because it checks if the value in that column is 2 rather than 1.WHERE id - 1 = 1is equivalent toWHERE id = 2but more confusing to the reader (thanks to FirstOne for pointing that out). - As mentioned in another answer, your code is vulnerable for SQL injection, I’d check this: https://stackoverflow.com/a/16282269/4283725
1
solved Why does this piece of code not work, when I pass value through input text?