concatenating part of variable name with value of another
Posted: Fri Jun 25, 2010 7:36 am
Hi
Trying to concatenate string '$num' with value in $j inside sql statement and keep getting a
truncated error on insertion.
Tried escaping With "\$num" but then the $value turns into a string instead of a variable.
Any help would be greatly appreciated
Thanks
Trying to concatenate string '$num' with value in $j inside sql statement and keep getting a
truncated error on insertion.
Tried escaping With "\$num" but then the $value turns into a string instead of a variable.
Any help would be greatly appreciated
Thanks
Code: Select all
$num1 = 'F';
$num2 ='T';
$num3 = 'F';
$num4 = 'F';
foreach ($_POST['answer'] as $value)
$j = 1;
{
$sql = "INSERT INTO answers SET
answer = '$value',
questionid = '$_POST[id]',
truefalse = '$num'.$j";//Trying to concatenate string '$num' and value of $j so as to end up with $num1on first iteration $num2 on second and so on.
$j++;
if (!mysqli_query($link, $sql))
{
$error = 'Error inserting answer into answers '
.mysqli_error($link);
include 'error.html.php';
exit();
}
}