-3

I want to perform a query. If the first fails then execute the second but it is saying:

MySQL ERROR: Unknown column 'status' in 'field list'

mysql_query("UPDATE `rolerota` SET `status`='$_GET[status]' WHERE `uid`='$_GET[id]'")  or die("MySQL ERROR: ".mysql_error()); 

mysql_query("UPDATE `showrota` SET `status`='$_GET[status]' WHERE `uid`='$_GET[id]'")  or die("MySQL ERROR: ".mysql_error()); 

They work fine in PHPMyAdmin, so I know the column does exist. Any ideas?

Thanks

Wouter J
  • 41,455
  • 15
  • 107
  • 112
  • 4
    [**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). – John Conde Dec 13 '12 at 15:36
  • 4
    Your code is wide open to [SQL injections](http://stackoverflow.com/q/60174) – John Conde Dec 13 '12 at 15:37
  • Completely agree with @JohnConde. As to your actual question it would be good for you to show us your table structure. – Cfreak Dec 13 '12 at 15:38
  • Figure out WHICH of those two queries is failing, then confirm that the field really does exist. – Marc B Dec 13 '12 at 15:40
  • 1
    It's a fairly self explanatory error message. There is no status column in either/both tables. -1 – piddl0r Dec 13 '12 at 15:41
  • Please check if you're using the same database as in PhpMyAdmin (I'm thinking about local modified tables, and both of your distant tables haven't `status` column yet, or a dev/prod databases duet). – zessx Dec 13 '12 at 15:46
  • Funny how you managed to make several critical errors in only 1 line of code :) – N.B. Dec 13 '12 at 16:01

1 Answers1

0

I will not comment on using mysqli as already suggested, make sure to upgrade when possible.

If it really does work on phpmyadmin then I will assume that the columns really exist and the problem isn't about that. So check the following things:

1) Maybe you are using different database servers on phpmyadmin and your code. Check your mysql_connect() to be sure.

2) Maybe you are using a different database on phpmyadmin and your code. Check your mysql_select_db() to be sure

3) Once that is done try this:

mysql_query("UPDATE rolerota SET status='".mysql_real_escape_string($_GET['status'])."' WHERE uid='".mysql_real_escape_string($_GET['id'])."'")  or die("MySQL ERROR 1: ".mysql_error()); 

mysql_query("UPDATE showrota SET status='".mysql_real_escape_string($_GET['status'])."' WHERE uid='".mysql_real_escape_string($_GET['id'])."'")  or die("MySQL ERROR 2: ".mysql_error());

you will get to know which query is failing depending on the message, you will also better protect your database against sql injection.

If that doesn't work then try posting the new error message and your database structure.

Mickle Foretic
  • 1,399
  • 12
  • 23
  • That didn't work - but I suppose it's a good idea to start creating the new scripts using PDO now which will save me time when I convert the entire website. Thanks for the suggestions – MrGuitarWizard Dec 13 '12 at 19:19