I have columns that their names have the structure nameUser.Name
, but I'm having trouble updating them. I've tried a few possibilities:
// Ideally, I'd like to do this (since the User.Name is 'dynamic', ie, it depends
// on who is logged in):
$userLogged = 'Some.User';
$columnName = 'name' . $userLogged;
mysql_query("UPDATE Industries SET '$columnName'='$name' WHERE id='$id'");
// Another try:
mysql_query("UPDATE Industries SET $columnName='$name' WHERE id='$id'");
// Alternatively, if the above cannot be achieved:
mysql_query("UPDATE Industries SET 'nameSome.User'='$name' WHERE id='$id'");
// Yet another try:
mysql_query("UPDATE Industries SET nameSome.User='$name' WHERE id='$id'");
Non of the above works, however. Why?
Because that is also the syntax for database.table.column
. Youll have to quote them like
`nameUser.name`
Though really, if you created/designed the db you should never use column names like that. Its just a horrible idea.
Instead of using single-quotes for the column name, use backticks (on most keyboards, to the left of the 1 key).
Like this:
mysql_query("UPDATE Industries SET `nameSome.User`='$name' WHERE id='$id'");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With