I am getting a value for return instead of my database information

StackOverflow https://stackoverflow.com/questions/22162228

  •  19-10-2022
  •  | 
  •  

Вопрос

I am getting a value for return instead of getting my data from my database. The code should be good. Here is my code:

function getConfigurationData($configuration_value, $configuration_name_value) {
$sql = "SELECT '".$configuration_value."' FROM configuration WHERE name = '".$configuration_name_value."'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
echo $row[$configuration_value];
}

<? getConfigurationData("value", "configuration_website_name"); ?>

What is wrong with my configuration. I seem not be returning my data and instead I get a value

Это было полезно?

Решение

your query is wrong (quotes around field name)

Try this

$sql = "SELECT ".$configuration_value." FROM configuration WHERE name = '".$configuration_name_value."'";

and a more readable way

$sql = "SELECT $configuration_value FROM configuration WHERE name = '$configuration_name_value'";
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top