I am trying to use a variable (string) as array key for a mysql select query in PHP script.
Here is the PHP code:
$newskill="'".$skill."_!skill'";
//$newskill="'Working_!skill'"; //Will be written into the var in the line above
$skill = array();
$time = array();
while($row = mysqli_fetch_array($getSkills))
{
$skill[] = $row[$newskill];
$time[] = $row['updated_at'];
}
I am getting this error:
Notice: Undefined index: 'Working_!skill' in ....\htdocs\skill\skilldiagram.php on line 71
But it works this way: Nothing changed but the content of the variable is printed hardcoded into the source code. This way it works perfectly fine.
$skill = array();
$time = array();
while($row = mysqli_fetch_array($getSkills))
{
$skill[] = $row['Working_!skill'];
$time[] = $row['updated_at'];
}