0

I have been trying several different configurations of this query and it will not update the record. If I run it in PHPmyAdmin it works fine but not if I use this:

mysql_query('update product set quantity = "7" where trum_num = "062-3104"');

Its becoming frustrating because this is so simple. Any help would be great. As an added note I am running this on Xampp server.

Also, I've looked at other similar questions here on Stack and none of those suggestions worked.

smack-a-bro
  • 691
  • 2
  • 13
  • 27
  • Have you got any error? – Hüseyin BABAL Apr 16 '14 at 13:47
  • "" or '' doesn't make any difference... are you connecting to you MySQL server, is the database selected, what error do you get? With just this single line of code it's impossible to know the answer... – patrick Apr 16 '14 at 13:48
  • Check the error message with `mysql_error()`. [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ) – Fracsi Apr 16 '14 at 13:48
  • http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks – fluminis Apr 16 '14 at 13:51
  • stupid question #1 ... have you actually connected to the database? stupid question #2 ... why are you trying to update what is, presumably, an `INT` type field with a string (even if your quote marks are backwards)? – CD001 Apr 16 '14 at 13:52
  • Please check `quantity` is `int` to remove "" in update query – Mehul Jethloja Apr 16 '14 at 13:56
  • 2
    I'm such a dumbass. I had written the connect code and tested some other queries and they worked fine. Then I need to write some new code so I commented out the other code, including the connect code. Didn't even look to check that as I testing it previously and it worked. Thanks for the obvious answer guys! – smack-a-bro Apr 16 '14 at 13:57
  • Even if quantity is an INT set quantity="7" or quantity='7' or quantity=7 would still work – patrick Apr 16 '14 at 13:58
  • @patrick depends on MySQL version IIRC... somewhere around 5.1x it got strict about it and started chucking errors when updating `INT` fields with string numeric data on my dev box ... not sure whether that's still the case though, I've moved to prepared statements since then. – CD001 Apr 16 '14 at 14:00

3 Answers3

0

Try this:

mysql_query("UPDATE `product` SET `quantity` = 7 WHERE `trum_num` = '062-3104' ;");
Reacen
  • 2,312
  • 5
  • 23
  • 33
  • works out as exactly the same query as the original... so I doubt this will be the answer. Probably it's a wrong connection, trum_num doesn't exist, the right for the user isn't enough, the server connection failed... something along those lines... – patrick Apr 16 '14 at 13:49
  • What have you tried to debug it ? Does this problem only occure when `UPDATE`ing ? – Reacen Apr 16 '14 at 13:52
0

try this:

you should remove the ' ' and add the " " like following as:

mysql_query("update product set quantity = '7' where trum_num = '062-3104' ");
jmail
  • 5,944
  • 3
  • 21
  • 35
  • different way of writing the exact same query... if this query works, so would the one in the initial question... – patrick Apr 16 '14 at 13:56
0

Can you make your code like this:

mysql_query('update product set quantity = "7" where trum_num = "062-3104"');
die(mysql_error());

and reply with the result? Most likely that will exactly what the problem is...

patrick
  • 11,519
  • 8
  • 71
  • 80