I have a page that I need to query a DB, put all the records in an array and then use the row info as variables in a while statement to create files.
Here is my code for getting the array info
<?php
require('/var/
$query = "SELECT * FROM assignments";
if ($result=mysqli_query($link,$query)) {
// Associative array
while ($row = mysqli_fetch_assoc($result)){
printf ("%s %s %s %s",$row["extension"],$row["secret"],$row["macaddress"],$row["template"]);
}
// Free result set
mysqli_free_result($result);
}
//Close Mysqli link
mysqli_close($link);
?>
This prints the needed info to my screen. This part was to test to make sure I was doing something right.
The info in the array needs to be used in this code:
copy('/var/ '/var/$template = "working.cfg";
$mac = "80.28.83.66.5f.23";
$extension = "102";
$secret = "aaasuda9841japsu9ajapdj";
$newname = "102";
$myfile = fopen("$template", "a") or die("Unable to open file!");
$txt = "account.1.display_name = $extension\n";
fwrite($myfile, $txt);
$txt = "account.1.auth_name = $extension\n";
fwrite($myfile, $txt);
$txt = "account.1.user_name = $extension\n";
fwrite($myfile, $txt);
$txt = "account.1.password = $secret\n";
fwrite($myfile, $txt);
$txt = "account.1.label = $extension\n";
fwrite($myfile, $txt);
fclose($myfile);
rename("$template", "$mac.cfg");
echo "The file creation is done";
mysqli_close($link);
It would replace the $mac, $template, $extension, and the $secret variables that I setup to test the file creation.
How do I do this?
Thanks in advance for any help.
Here is my code for getting the array info
<?php
require('/var/
$query = "SELECT * FROM assignments";
if ($result=mysqli_query($link,$query)) {
// Associative array
while ($row = mysqli_fetch_assoc($result)){
printf ("%s %s %s %s",$row["extension"],$row["secret"],$row["macaddress"],$row["template"]);
}
// Free result set
mysqli_free_result($result);
}
//Close Mysqli link
mysqli_close($link);
?>
This prints the needed info to my screen. This part was to test to make sure I was doing something right.
The info in the array needs to be used in this code:
copy('/var/ '/var/$template = "working.cfg";
$mac = "80.28.83.66.5f.23";
$extension = "102";
$secret = "aaasuda9841japsu9ajapdj";
$newname = "102";
$myfile = fopen("$template", "a") or die("Unable to open file!");
$txt = "account.1.display_name = $extension\n";
fwrite($myfile, $txt);
$txt = "account.1.auth_name = $extension\n";
fwrite($myfile, $txt);
$txt = "account.1.user_name = $extension\n";
fwrite($myfile, $txt);
$txt = "account.1.password = $secret\n";
fwrite($myfile, $txt);
$txt = "account.1.label = $extension\n";
fwrite($myfile, $txt);
fclose($myfile);
rename("$template", "$mac.cfg");
echo "The file creation is done";
mysqli_close($link);
It would replace the $mac, $template, $extension, and the $secret variables that I setup to test the file creation.
How do I do this?
Thanks in advance for any help.