...

View Full Version : Problem feeding PHP into framework



swiltch
03-06-2012, 03:55 PM
Hello, I'm hoping someone can help me with this.

I have 3 pages that I need to put into my framework, they are products, shopping cart and billing. At the moment they work perfectly fine. Here is a live example -

http://www.cems.uwe.ac.uk/~r4-george/wp2/shopping/products.php

Now, I have a framework for a whole website that I need to put these pages into. (http://www.cems.uwe.ac.uk/~r4-george/wp4/index.php) The index uses a switch statement to go between pages.

Here is the index.php



<?php # index.php

/*
* This is the main page.
* This page includes the configuration file,
* the templates, and any content-specific modules.
*/

// Require the configuration file before any PHP code:
require_once ('./modules/config.inc.php');

// Validate what page to show:
if (isset($_GET['p'])) {
$p = $_GET['p'];
} elseif (isset($_POST['p'])) { // Forms
$p = $_POST['p'];
} else {
$p = NULL;
}

// Determine what page to display:
switch ($p) {

case 'about':
$page = 'about.inc.php';
$page_title = 'About This Site Again';
break;

case 'products':
$page = 'products.inc.php';
$page_title = 'Products on this site';
break;

case 'this':
$page = 'this.inc.php';
$page_title = 'This is Another Page.';
break;

case 'that':
$page = 'that.inc.php';
$page_title = 'That is Also a Page.';
break;

case 'contact':
$page = 'contact.inc.php';
$page_title = 'Contact Us';
break;

case 'search':
$page = 'search.inc.php';
$page_title = 'Search Results';
break;

// Default is to include the main page.
default:
$page = 'main.inc.php';
$page_title = 'Site Home Page';
break;

} // End of main switch.

// Make sure the file exists:
if (!file_exists('./modules/' . $page)) {
$page = 'main.inc.php';
$page_title = 'Site Home Page';
}

// Include the header file:
include_once ('./includes/header.inc');


echo "<div id=\"content\">";

// Include the content-specific module:
// $page is determined from the above switch.
include ('./modules/' . $page);

// Include the footer file to complete the template:
include_once ('./includes/footer.inc');

?>


It uses the .inc.php files located in the modules folder to switch between pages.

Here is my products.inc.php -


<?php # index.php

/*
* This is the main page.
* This page includes the configuration file,
* the templates, and any content-specific modules.
*/

// Require the configuration file before any PHP code:
require_once ('./modules/config.inc.php');

// Validate what page to show:
if (isset($_GET['p'])) {
$p = $_GET['p'];
} elseif (isset($_POST['p'])) { // Forms
$p = $_POST['p'];
} else {
$p = NULL;
}

// Determine what page to display:
switch ($p) {

case 'about':
$page = 'about.inc.php';
$page_title = 'About This Site Again';
break;

case 'products':
$page = 'products.inc.php';
$page_title = 'Products on this site';
break;

case 'this':
$page = 'this.inc.php';
$page_title = 'This is Another Page.';
break;

case 'that':
$page = 'that.inc.php';
$page_title = 'That is Also a Page.';
break;

case 'contact':
$page = 'contact.inc.php';
$page_title = 'Contact Us';
break;

case 'search':
$page = 'search.inc.php';
$page_title = 'Search Results';
break;

// Default is to include the main page.
default:
$page = 'main.inc.php';
$page_title = 'Site Home Page';
break;

} // End of main switch.

// Make sure the file exists:
if (!file_exists('./modules/' . $page)) {
$page = 'main.inc.php';
$page_title = 'Site Home Page';
}

// Include the header file:
include_once ('./includes/header.inc');


echo "<div id=\"content\">";

// Include the content-specific module:
// $page is determined from the above switch.
include ('./modules/' . $page);

// Include the footer file to complete the template:
include_once ('./includes/footer.inc');

?>


This is EXACTLY the same code as the working example. The products get listed correctly but the problem I have is the 'Add to Cart' button fails to work.

Live example - http://www.cems.uwe.ac.uk/~r4-george/wp4/index.php?p=products

Everything is in the right directory. When I inspect the 'Add to Cart' button in chrome I get the following -



Uncaught TypeError: Cannot set property 'value' of undefined
addtocartindex.php:51
(anonymous function)index.php:83
onclick

Any help is really appreciated, I'm struggling to see what I have done wrong. I don't know whether it's a Javascript problem.

If you need any of the code from other pages I can post it too.

Thanks in advance.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum