-1
$q = "update men SET price-1='$first' WHERE id='1'";

if($db->query($q))
    {
        echo "<script> alert('Data Has Been Updated Successfully ')</script>";
    }

The error in the column name price-1, If my column name is like price then it works but not with price-1

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Zaid Butt
  • 35
  • 1
  • 1
  • 7
  • Do you mean `$q = "update men SET price='$first'-1 WHERE id='1'";` instead ? – Rubik Mar 05 '15 at 12:25
  • Do you have a column called `price-1`, or are you trying to reduce the value of the price column by one? – stwalkerster Mar 05 '15 at 12:29
  • possible duplicate of [When to use single quotes, double quotes, and backticks?](http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks) – Artjom B. Mar 05 '15 at 12:45

2 Answers2

1

You might need to escape your column name

$q = "update men SET `price-1`='$first' WHERE id='1'";
CT14.IT
  • 1,635
  • 1
  • 15
  • 31
0

Surround the column name price-1 in quotes 'price-1' and try again. The quote is this ` just it won't let me write it. It's the one under the Escape. I noticed my mystake.

Luchiro
  • 53
  • 5
  • Why don't you make the column name price_1 or price1. That hyphen is hard and annoying to handle. I suggest not using it when naming be it variables, column names, etc. Not that it's impossible but it's just unneccessary pain. – Luchiro Mar 05 '15 at 12:32
  • yeah, you are write, thnaks for helping me. – Zaid Butt Mar 05 '15 at 12:34