0

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'];
}

1 Answer 1

2

You don't need the literal quotes in $newskill. It should be:

$newskill=$skill."_!skill";
Sign up to request clarification or add additional context in comments.

1 Comment

Works ty. That was fast and I feel like an idiot now :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.