1

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!

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
rhill45
  • 559
  • 10
  • 35
  • 4
    Step one: [Enable error reporting](http://stackoverflow.com/a/6575502/1438393). – Amal Murali Feb 26 '14 at 15:08
  • Thank you amal, I have the IF statement echoing an error for the ID data. Are you referring to the server logs or more error announcements within the script? – rhill45 Feb 26 '14 at 15:14
  • Apologies, I found answer for that, thank you again Amal. ERROR REPORTING: http://stackoverflow.com/questions/6575482/how-do-i-enable-error-reporting-in-php?lq=1 – rhill45 Feb 26 '14 at 15:17
  • Note that you're injecting variables into your SQL query, hence you open up for hackers. Magically changing `mysql_` to `mysqli_` does not fix this. Use prepared statements and bind variables. – h2ooooooo Feb 26 '14 at 15:22

0 Answers0