After a user selects a sql row, a href echo's the unique operator $id to a script on another file. The script: 1.reads a template page (single-page.php). This template page has scattered throughout it tags delimitated as so: {title2}, {img_link2} etc... 2. The script should substitute for the tags data from sql corresponding to the $id. 3. finally the script should save the file to a location denoted by $page_path, a value also in sql that corresponds to the unique $id.
When click on a sql row the url changes to the page the script is on but it doesn't proceed. If I view source file it shows just the number 1 in its corner. Script :
if(isset($_GET['id'])){
$idrt=$_GET['id'];
include("db.php");
$query="SELECT * FROM `stories` WHERE id=$idrt";
$result=mysqli_query($connection,$query);
while ($data = mysqli_fetch_assoc($result)):
$id = $data['id'];
$title = $data['title'];
$page_path = $data['page_path'];
$template = file_get_contents("single-page.php");
$contents = str_replace("{title2}", $title, $template);
file_put_contents($page_path, $contents);
endwhile;
mysqli_close($connection);
}else echo "error on ID data";
I've checked the file permissions and they are 777 for the folder the file should save to and for the template file. 1.The script is not working, does anyone see why? 2.I'm concerned file_put_contents is not going to work for this project to begin with because it is going to delete the page. With using APPEND_DATA mode I'm not certain it will be able to fill in my tags which are scattered throughout the file. 3.I'm open to other ways of doing this
Thank you in advance!