0
Is there any way to do an Update in mysql where only let update the data if the column is empty.
Imagine 4 radio input (the radios will be 1 at a time is not)
Ai if a user(x) chooses radio 1 and saves, and user(y) chooses radio 2 and saves
- Ai What happens with input radio 1 ???? the post is empty consequently erasing the data in mysql and this I do not want to occur
Example
Data table
__________________________________________
| id | valor1 | valor2 | valor3 | Valor4 |
| 1 | 20 | | 20 | |
$valor1 = $_post['valor1']; //post vasio
$valor2 = $_post['valor2']; //post vasio
$valor3 = $_post['valor3']; //post vasio
$valor4 = $_post['valor4']; //post vasio
$sql = mysql_query ("INSERT INTO dados(valor1,valor2,valor3,valor4)
VALUES('$valor1','$valor2','$valor3','$valor4',)",
$conexao) or die( mysql_error());
se os post vierem vazios, vão apagar os dados que já estão na base
In the column value1 and Valor3 there are inserted values, I would like a way to lock these values and not let change
Check if this is not a XY problem. It may be that the answers are more necessary by asking the initial problem to be solved.
– Bacco
As @Acco said in their comment, you are looking for an incorrect solution to your problem. Mysql does not allow this type of lock. You should validate this with php itself on screen. be updating the information when saving or restructuring the modeling of your database that seems confusing to me
– Ari
The update slightly improved the question, but revealed a problem: storing a radio input in 4 different columns is probably unnecessary. Another problem is that you don’t test in your code whether a post was sent or not. Another problem is that your code is an INSERT, it doesn’t even make sense to talk in empty columns. Insert always creates a new row. I would suggest going back a few steps in its development and fixing these things (mastering the concepts) before proceeding, because the further it advances the more confusing the code becomes, and will increasingly require patches.
– Bacco
With the modification, my answer becomes meaningless. And so is the problem itself. It seems to be more of a business logic problem. Something +- as @Ari commented.
– Daniel Omine