update sql function + php not working properly

Asked

Viewed 28 times

1

i needed to do something very basic, I am creating a customer site and I need to create the function of decreasing in 1 the client portion in db, follows below the function that I set up

function quit() {     
  $sql ="UPDATE customers SET parcelas = parcelas - 1 WHERE id = ". $_SESSION['id'] .";";      
}

I created a form on the View page and put the action to redirect to a separate php with the post method, set the function on this page with the session already started and called the function, but nothing happens, I am redirected to the main page without success. I already called a Var_dump and the problem is not in the variable, I also confirmed that it was not using varchar instead of int in the table. I have tried to manually put the id and also the value of plots, but it also did not work. I even tried to put without Where to see if the db was all updated but just doesn’t work, if anyone can help me I would be grateful.

update: I talked to a friend and he reminded me of the command mysqli_query, the code then was like this:

function quit() {     
  $sql ="UPDATE customers SET parcelas = parcelas - 1 WHERE id = ". $_SESSION['id'];   
$result = mysqli_query($sql);
}

quit();

but still I had no positive result

  • First put the parcel amount into a variable then update

  • @Bernardolopes why do this if the update command itself already does this?

  • already took the value of the variable $sql and tried to run right into the bank? and the rest of the code, it can’t be a problem in the commands running this update?

  • If I well noticed Window is subtracting 1 from the column. "parcels" is the column name, Window does not have the amount of parcels. This updating the column "plots" with "plots" -1

  • i manually tested the command in phpmyadmin and it worked correctly, and on the commands, I called the function in the same php file as I have used in the project

  • 1

    Try it this way $sql ="UPDATE customers SET parcelas = parcelas - 1 WHERE id = $_SESSION['id']";

  • will not work pq nn ta concatenating with php, nn will neither recognize the code

Show 2 more comments
No answers

Browser other questions tagged

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