I have a script that creates some variables (var1, var2, var3 ...) on the fly and sends them to a second script through a form. In the second script I need to recreate these variable names and update a database, as follows:
$check = 1;
while ($row = mysql_fetch_array($sql_result)) {
$record1 = $row["record1"];
$record2 = $row["record2"];
$a = "\$var{$check}"; // <= here is the problem
$sql = "UPDATE table SET record1 = '$a' WHERE record2 = '$xyz'";
$sql_result = mysql_query ($sql, $connection) or die ("Failed update");
$check = $check+1;
}
I am trying to recreate the variable names ($var1, $var2, $var3 ...) under $a in the second script, and then update the database. The variable name gets created, but the values from the first script are not picked up. I am doing something wrong. Any help will be appreciated. Thank you.