Jump to content

fersick

Members
  • Posts

    5
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

fersick's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. All files have .PHP as the extention. I'm on my phone qtm. Will check the source code tomorrow when I'm at my pc
  2. I'm running code from my htdoc folder in xampp using localhost or 127.0.0.1
  3. I have been working through the text book. Practical PHP by Paul Hudson. The chapter on creating a simple OOP site. wont render in a browser. I have written the code out get not errors in the debugging console i see my rendered HTML code in the console. But in a browser i get code setPage($page); $content = <<setContent($content); $site->render(); ?> These are the files i have written index.php <?php include 'stdlib.php'; error_reporting(E_ALL); ini_set('display_errors', 1); $site = new csite(); // This is a function specific to this site! initialise_site($site); $page = new cpage("Welcome to my site!"); $site->setPage($page); $content = <<<EOT Welcome to my personal web site! EOT; $page->setContent($content); $site->render(); ?> I feel it has something to do with the EOT reference, as the code surrounding the EOT is what is outputted in browser. stlib.php <?php function __autoload($class) { include "$class.php"; } function initialise_site(csite $site) { $site -> addHeader("header.php"); $site -> addFooter("footer.php"); } ?> csite.php <?php class csite { private $headers; private $footers; private $page; public function __construct() { $this -> headers = array(); $this -> footers = array(); } public function __destruct() { // clean up here. } public function render() { foreach ($this->headers as $header) { include $header; } $this->page->render(); foreach ($this->footers as $footer) { include $footer; } } public function addHeader($file) { $this -> headers[] = $file; } public function addFooter($file) { $this -> footers[] = $file; } public function setPage(cpage $page) { $this -> page = $page; } } ?> cpage.php <?php class cpage { private $title; private $constant; public function __construct($title) { $this -> title = $title; } public function __destruct() { // clean up here } public function render() { echo "<H1>{$this->title}</H1>"; echo $this -> content; } public function setContent($content) { $this -> content = $content; } } ?> header.php and footer.php are just basic HTML code.
  4. thank for this. Regarding the other posts. Thanks also. With the echo before the header. I thought that this only was an issue directly before the header call. guess not. Thanks
  5. I have a function that will generate a table of products. Each <tr> is a form of its own. When i log in to my site and start a session the user can add products to there cart. This all works fine except if you try and add a second product from the same page. If you do this you get an error : Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\workspace\Assignment3\global\products.php:19) in C:\xampp\htdocs\workspace\Assignment3\global\products.php on line 66 CODE: SELECT ALL function products($product) { $file = "data/products.txt"; $fp = fopen($file, 'r'); $count = 0; while (!feof($fp)) { $data = fgets($fp); $section = explode(":" , $data); if($product == $section[0]) { echo ' <form action="" method="post" onsubmit=""> <br /> <table> <tr class="order"> <td class="item1"><img src="'. $section[1] . '" height="94" width="96"></img></td> <th class="itemHeader">'; $productName = $section[2]; echo $productName . '<input type="hidden" name="Product' . $count . '" value="' . $productName. '" /> </th> <td class="product"><b>'.$section[3] .':</b> ' . $section[4] . '<br /> <b>' . $section[5]; // used because of : delimiter could have used something else.. if ($product == 'Soap') { echo ':</b> ' . $section[6] . '<br /></td>' ; } else { echo '</b>' . $section[6] . '<br /></td>'; } echo '<td class="product"><b>Price: '; $productPrice = $section[7]; echo '$' . $productPrice . '</b><input type="hidden" name="Price' . $count . '" value="' . $productPrice.'" /> </td>'; if (!empty($_SESSION['userName'])) { echo '<td class="submitItem"><input type="text" size="3" maxlength="3" name="Qty'. $count . '"value="0" /> '; echo '<input type="submit" value="Add to Cart" name="submit' . $count . '" id="submitItem" />'; } echo '</td> </tr> </table> </form>'; // stores the required information in Session variables if (isset($_POST['submit' . $count])) { $index = $count; $_SESSION[$product . 'Name' . $index] = $_POST['Product' . $index]; $_SESSION[$product .'Price' . $index] = $_POST['Price' . $index]; if (empty($_SESSION['soapQty' . $index])) { $_SESSION[$product . 'Qty' . $index] = $_POST['Qty' . $index]; } else { $_SESSION[$product . 'Qty' . $index] = $_SESSION[$product . 'Qty' . $index] + $_POST['Qty' . $index]; } $_SESSION['cart'] = true; $_SESSION['globalQty'] += $_SESSION[$product . 'Qty' . $index]; header('Location: home.php'); exit; } } $count++; } $_SESSION[$product . 'Count'] = $count; } So basically the first call to this function's isset works but any consecutive call to isset for another product of the same type doesn't. I have read about white space and text before a header call but can't see how that is the problem here. Also read the sticky. Any help would be greatly appreciated p.s. I appologise for the $_SESSION variable declaration as a chain and NOT as an array for me to change my code in my assignment at this stage would take too long.
×
×
  • 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.