Updating data in SQL

Asked

Viewed 112 times

3

I have a table with the following fields: Nome(VARCHAR), Email(VARCHAR), Credito(INT)

I wanted to know how, or with what command, I do to decrease or enlarge the field Credito.

I know you have to use the UPDATE but I’ve tried several ways and I haven’t been able to.

  • If you want a more focused response, put what database you’re using, what PHP technology you’re using to access it, and if possible how you’re trying to do the update same as wrong. Try to put a code of what you tried. Then it is easier to indicate where you are missing.

1 answer

6


You haven’t given a lot of details of what you’re using, or shown what you tried so I’ll give you a generic answer to increment the value of one for the field in Mysql that I think is the likely DB you’re using (I’d better focus more on your question):

$sql = "UPDATE tabela SET Credito = Credito + 1 WHERE Email = '$email'";
$resultado = mysqli_query($conexao, $sql)

I put in the Github for future reference.

I’m assuming the variable is properly sanitized.

Or you can use a parameterized form to execute but the query SQL will be the same as above.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.