1
$sql="UPDATE users SET TN4='1', Notificare4='1', Neachitate='1' WHERE username='$user'";

This works fine. It sets Neachitate row into 1. But, I want to set it to $Neachitate+ 1 ( +1 value, like each time you click it adds one more)

So, I modified it with

$Neachitate = $row['Neachitate']; // it gets what value is in Neachitate, right?

    $sql3="UPDATE users SET TN4='1', Notificare4='1', Neachitate='$Neachitate + 1' WHERE username='$user'";

But this time it sets to 0. Why?

2 Answers 2

1

Use

$sql3="UPDATE users SET TN4='1', Notificare4='1', Neachitate=Neachitate + 1 WHERE username='$user'";

instead.

You're trying to save Neachitate='$Neachitate + 1': this is a string, not a number.

Sign up to request clarification or add additional context in comments.

Comments

1

More generally, eliminate the single quotes! And use parameters!

UPDATE users
    SET TN4 = 1,
        Notificare4 = 1,
        Neachitate = ? + 1
    WHERE username = ?;

Single quotes should only be used for string and date constants. Parameters should always be used for passing constant values into queries.

1 Comment

thank you for your time and explications. I'll learn better from stackoverfllow than any school / studies. Yeah, if only I wouldn't get downvotes because I don't understand something and asking it (even if I read something close to my question and still don't get it.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.