Jump to content

output php code to a text file


snnbbc

Recommended Posts

Hello,

 

I would like to ask if anyone knows how to output the following php code into a text file. The code is inside the body tags of an html page. I know that with the fwrite(); function I can save a variable to a text file, but in this code I have a while statement which can output several lines of code. I would like to save the output from the while statement and the $total to the text file. Here is the code:

 

<?php

$cnt = array();

$products = array();

 

foreach($_POST as $key=>$value)

  {

    $key=(int)str_replace('_cnt','',$key);

    $products[]=$key;

    $cnt[$key]=$value;

  }

 

$result = mysql_query("SELECT * FROM internet_shop WHERE id IN(".join($products,',').")");

 

if(!mysql_num_rows($result))

  {

      echo '<h1>There was an error with your order!</h1>';

  }

else

  {

      echo '<h1>You ordered:</h1>';

 

      while($row=mysql_fetch_assoc($result))

          {

  echo '<h2>'.$cnt[$row['id']].' x '.$row['name'].'</h2>';

  $total+=$cnt[$row['id']]*$row['price'];

          }

 

          echo '<h1>Total: $'.$total.'</h1>';

  }

?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.