0

I have some problems with a query in MySQL.

I use the character set UTF-8, which I have set in the header.

the connection to MySQL is also set with

mysql_set_charset("utf8", $conn);

My database uses utf8_general_ci

When i echo my query and manually insert it inside phpMyAdmin it works fine.

e.g.

SELECT `project_number` FROM `1` WHERE `project_name`='æøå'

But when I insert this query

$row = mysql_fetch_assoc(mysql_query("SELECT `project_number` FROM `$user_id` WHERE `project_name`='$project_name'"));
$project_number = $row['project_number'];

project_number returns nothing, when i use special characters like æøå, but works when I don't use æøå.

user3805674
  • 221
  • 1
  • 5
  • 4
    Do you really have a table called `1`? Why don't you have a single `projects` table including a `user_id` column? – Mark Baker Jul 25 '14 at 22:00
  • Why aren't you looking at `mysql_error`? – Quentin Jul 25 '14 at 22:08
  • You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Jul 25 '14 at 22:09

1 Answers1

0

You really shouldn't be using a numerical value as a table name.

More information about that can be found in the MySQL Documentation

If you do need to use numerical table names then you'll have to use an identifier quote. Regardless, I'd recommend based on your current example to create a table called user_1, where 1 is the ID of that user.

This still isn't a proper solution. The comment that Mark Baker gave you is a much better idea and way of doing things.

It should also be pointed out that mysql_* functions are depreciated now and it's highly recommended that you stop using them. Check out the MySQLi Functions that PHP has to offer or find another PDO style function.

Diemuzi
  • 3,507
  • 7
  • 36
  • 61