Jump to content

Odd problem with php + post(i think)


smokewon

Recommended Posts

Hi there, basically in the files attached, theres the web page called "products.php" which makes use of the php "include" within, the page allows users to click on a router brand, which *should* display the corresponding router models of that brand, also buttons per model, if the user clicks on one of those router model buttons it should show more infomation about that router, this does work and without error, however only 1 of the router brands/models is being displayed where as the others are not at all, im very stumped because i know theres no broken links in the mysql database and what not because i display the router model infomation randomly on the home page, any help MUCH appreciated as im very very very stumped

 

sorry i cant seem to be able to attach files, so ill paste the code here:

 

home page (home.php)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="style.css" >
	<title>Home</title>
</head>

<body>

<?php include('apps/ecomDB.php');?>

<div id="header">
	<object type="application/x-shockwave-flash" data="webbanner1.swf">
		<param name="movie" value="webbanner1.swf">
	</object>
</div>

<div id="navbar">
	<ul>
		<li><a href="home.php">Home</a></li>
		<li><a href="products.php">Products</a></li>
		<li><a href="#">About/Contact</a></li>
		<li><a href="#">Login</a></li>
		<li><a href="#">Register</a></li>
	</ul>
</div>

<div id="sidebar">
	<?php include('apps/sidebar.php');?>
</div>

<div id="mainContent">
	<?php include('apps/specials.php'); ?>
</div>

<div id="footer">
</div>

</body>
</html>

 

products.php:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="style.css" >
	<title>Home</title>
</head>

<body>

<?php include('apps/ecomDB.php');?>

<div id="header">
	<object type="application/x-shockwave-flash" data="webbanner1.swf">
		<param name="movie" value="webbanner1.swf">
	</object>
</div>

<div id="navbar">
	<ul>
		<li><a href="home.php">Home</a></li>
		<li><a href="products.php">Products</a></li>
		<li><a href="#">About/Contact</a></li>
		<li><a href="#">Login</a></li>
		<li><a href="#">Register</a></li>
	</ul>
</div>

<div id="sidebar">
	<?php include('apps/sidebar.php');?>
</div>

<div id="mainContent">
	<div id="modelNav">
		<?php include('apps/modelNav.php')?>
	</div>
	<div id="productDisplay">
		<?php include('apps/proDisplay.php')?>
	</div>
</div>

<div id="footer">
</div>

</body>
</html>

 

specials.php:

<?php

echo  '<h2>Special Offers</h2>';

$specialOffer = mysql_query("SELECT * FROM router_models ORDER BY RAND() LIMIT 0,1");

while($row=mysql_fetch_array($specialOffer, MYSQL_ASSOC) or die(mysql_error())){

	if($row[rModel_B]==1)
		echo '<p>Cisco</p>';
	else if($row[rModel_B]==2)
		echo '<p>Dynalink</p>';
	else if($row[rModel_B]==3)
		echo '<p>NetGear</p>';
	else if($row[rModel_B]==4)
		echo '<p>D-Link</p>';
	else
		echo '';

	echo '<img src="/ECOMSite/images/'.$row['rModel_IMG'].'">';
	echo '<p>'.$row[rModel_name].'</p>';
	echo '<p>'.$row[rModel_type].'</p>';
	echo '<p>'.$row[rModel_speed].'</p>';
	echo '<p>'.$row[rModel_RJ45].'</p>';
	echo '<p>'.$row[rModel_price].'</p>';
}

?>

 

sidebar.php:

<?php 

$query = mysql_query("SELECT rBrand_ID, rBrand_name FROM router_brands");

if(!$query){
echo 'Invalid query: '.mysql_error().'';
}
while($row = mysql_fetch_array($query, MYSQL_ASSOC)){
	if($row[rBrand_ID]==1)
	{
		echo '<form action="products.php" method="post">
			<input type="submit" name="ID" value='.$row[rBrand_name].'></form>';
	}
	else if($row[rBrand_ID]==2)
	{
		echo '<form action="products.php" method="post">
			<input type="submit" name="ID" value='.$row[rBrand_name].'></form>';
	}
	else if($row[rBrand_ID]==3)
	{
		echo '<form action="products.php" method="post">
			<input type="submit" name="ID" value='.$row[rBrand_name].'></form>';
	}
	else if($row[rBrand_ID]==4)
	{
		echo '<form action="products.php" method="post">
			<input type="submit" name="ID" value='.$row[rBrand_name].'></form>';
	}
	else
		echo "Error";
}

?>

 

proDisplay.php:

<?php

echo '<fieldset>';

$sql = 'SELECT * FROM router_models WHERE rModel_name = "'.$_POST['model'].'"';

$query =  mysql_query($sql);

if(!$query){
	echo 'Invalid Query: '.mysql_error().'';
}

while($row = mysql_fetch_array($query)){
	echo '<img src="/ECOMSite/images/'.$row['rModel_IMG'].'">';
	echo '<p>'.$row[rModel_name].'</p>';
	echo '<p>'.$row[rModel_type].'</p>';
	echo '<p>'.$row[rModel_speed].'</p>';
	echo '<p>'.$row[rModel_RJ45].'</p>';
	echo '<p>'.$row[rModel_price].'</p>';
}
echo '</fieldset>';

?>

 

modelNav.php:

<?php

echo '<fieldset>';

$sqlQuery = 'select rModel_name, rBrand_ID from router_models, router_brands'.
	' where router_models.rModel_B = router_brands.rBrand_ID'.
		' and router_brands.rBrand_name = "'.$_POST['ID'].'"';


$query = mysql_query($sqlQuery);

if(!$query){
	die('Invalid Query: ' .mysql_error());
}

while($row = mysql_fetch_array($query)){
	echo '<form action="" method="post"><input type="submit"
		value='.$row[rModel_name].' name="model"></form>';
}

echo '</fieldset>';
?>

 

and the sql dump:

-- MySQL dump 10.11
--
-- Host: localhost    Database: ecom_dev
-- ------------------------------------------------------
-- Server version	5.0.51a-3ubuntu5.1

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Current Database: `ecom_dev`
--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `ecom_dev` /*!40100 DEFAULT CHARACTER SET latin1 */;

USE `ecom_dev`;

--
-- Table structure for table `account`
--

DROP TABLE IF EXISTS `account`;
SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `account` (
  `acc_ID` smallint(6) NOT NULL auto_increment,
  `acc_login` varchar(20) NOT NULL,
  `acc_pwd` varchar(20) NOT NULL,
  `acc_reg` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `customers_cust_ID` smallint(6) NOT NULL,
  PRIMARY KEY  (`acc_ID`,`customers_cust_ID`),
  KEY `fk_account_customers` (`customers_cust_ID`),
  CONSTRAINT `fk_account_customers` FOREIGN KEY (`customers_cust_ID`) REFERENCES `customers` (`cust_ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
SET character_set_client = @saved_cs_client;

--
-- Dumping data for table `account`
--

LOCK TABLES `account` WRITE;
/*!40000 ALTER TABLE `account` DISABLE KEYS */;
/*!40000 ALTER TABLE `account` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `account_orders`
--

DROP TABLE IF EXISTS `account_orders`;
SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `account_orders` (
  `accID_order` smallint(6) NOT NULL,
  `acc_order_date` date NOT NULL,
  PRIMARY KEY  (`accID_order`),
  CONSTRAINT `account_orders_ibfk_1` FOREIGN KEY (`accID_order`) REFERENCES `account` (`acc_ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
SET character_set_client = @saved_cs_client;

--
-- Dumping data for table `account_orders`
--

LOCK TABLES `account_orders` WRITE;
/*!40000 ALTER TABLE `account_orders` DISABLE KEYS */;
/*!40000 ALTER TABLE `account_orders` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `customers`
--

DROP TABLE IF EXISTS `customers`;
SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `customers` (
  `cust_ID` smallint(6) NOT NULL auto_increment,
  `cust_first` char(20) NOT NULL,
  `cust_last` char(20) NOT NULL,
  `cust_email` varchar(60) NOT NULL,
  `cust_phone` int(11) NOT NULL,
  `cust_street` varchar(100) NOT NULL,
  `cust_suburb` char(20) NOT NULL,
  `cust_town` char(20) NOT NULL,
  PRIMARY KEY  (`cust_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
SET character_set_client = @saved_cs_client;

--
-- Dumping data for table `customers`
--

LOCK TABLES `customers` WRITE;
/*!40000 ALTER TABLE `customers` DISABLE KEYS */;
/*!40000 ALTER TABLE `customers` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `order_routers`
--

DROP TABLE IF EXISTS `order_routers`;
SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `order_routers` (
  `order_router_ID` smallint(6) NOT NULL,
  `order_model` tinyint(4) NOT NULL,
  `router_models_rModel_ID` tinyint(4) default NULL,
  PRIMARY KEY  (`order_router_ID`),
  KEY `fk_order_routers_router_models` (`router_models_rModel_ID`),
  CONSTRAINT `fk_order_routers_router_models` FOREIGN KEY (`router_models_rModel_ID`) REFERENCES `router_models` (`rModel_ID`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `order_routers_ibfk_1` FOREIGN KEY (`order_router_ID`) REFERENCES `orders` (`order_account_ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
SET character_set_client = @saved_cs_client;

--
-- Dumping data for table `order_routers`
--

LOCK TABLES `order_routers` WRITE;
/*!40000 ALTER TABLE `order_routers` DISABLE KEYS */;
/*!40000 ALTER TABLE `order_routers` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `orders`
--

DROP TABLE IF EXISTS `orders`;
SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `orders` (
  `order_account_ID` smallint(6) NOT NULL,
  `order_ID` smallint(6) NOT NULL,
  `order_status` enum('Shipped','Processing') NOT NULL,
  PRIMARY KEY  (`order_account_ID`,`order_ID`),
  CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`order_account_ID`) REFERENCES `account_orders` (`accID_order`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
SET character_set_client = @saved_cs_client;

--
-- Dumping data for table `orders`
--

LOCK TABLES `orders` WRITE;
/*!40000 ALTER TABLE `orders` DISABLE KEYS */;
/*!40000 ALTER TABLE `orders` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `router_brands`
--

DROP TABLE IF EXISTS `router_brands`;
SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `router_brands` (
  `rBrand_ID` tinyint(4) NOT NULL auto_increment,
  `rBrand_name` varchar(20) NOT NULL,
  PRIMARY KEY  (`rBrand_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
SET character_set_client = @saved_cs_client;

--
-- Dumping data for table `router_brands`
--

LOCK TABLES `router_brands` WRITE;
/*!40000 ALTER TABLE `router_brands` DISABLE KEYS */;
INSERT INTO `router_brands` VALUES (1,'Cisco'),(2,'Dynalink'),(3,'NetGear'),(4,'D-Link');
/*!40000 ALTER TABLE `router_brands` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `router_models`
--

DROP TABLE IF EXISTS `router_models`;
SET @saved_cs_client     = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `router_models` (
  `rModel_ID` tinyint(4) NOT NULL auto_increment,
  `rModel_B` tinyint(4) NOT NULL,
  `rModel_name` varchar(20) NOT NULL,
  `rModel_type` varchar(30) NOT NULL,
  `rModel_speed` varchar(20) NOT NULL,
  `rModel_RJ45` tinyint(4) NOT NULL,
  `rModel_price` decimal(6,2) NOT NULL,
  `rModel_IMG` text NOT NULL,
  `rModel_desc` text NOT NULL,
  PRIMARY KEY  (`rModel_ID`),
  KEY `rModel_B` (`rModel_B`),
  CONSTRAINT `router_models_ibfk_1` FOREIGN KEY (`rModel_B`) REFERENCES `router_brands` (`rBrand_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=latin1;
SET character_set_client = @saved_cs_client;

--
-- Dumping data for table `router_models`
--

LOCK TABLES `router_models` WRITE;
/*!40000 ALTER TABLE `router_models` DISABLE KEYS */;
INSERT INTO `router_models` VALUES (1,1,'Cisco 888','Router','10/100 Mbs',4,'89.95','888.JPG',''),(2,1,'Cisco 881','Router','10/100 Mbs',4,'99.95','881.jpg',''),(3,1,'Cisco 878','Router','10/100 Mbs',4,'120.95','878.jpg',''),(4,1,'Cisco 877','Router','10/100 Mbs',4,'165.95','877.JPG',''),(5,1,'Cisco 876','Router','10/100 Mbs',4,'199.95','876.JPG',''),(6,2,'DYWRT54','Router/Firewall','10/100 Mbs',4,'112.95','DYWRT54.jpg',''),(7,2,'NET-NB6PLUS4W','Router/Firewall','10/100 Mbs',4,'148.95','NB6PLUS4W.jpg',''),(8,2,'NV-600R','Switch/Router','10/100 Mbs',4,'275.95','NV-600R.jpg',''),(9,3,'FVS336G Prosafe Dual','Firewall','10/100/1000 Mbs',4,'605.95','FVS336G.jpg',''),(10,3,'FVS338 ProSafe VPN','Firewall','10/100 Mbs',4,'329.95','FVS338.jpg',''),(11,3,'FVX538 ProSafe VPN','Switch/Firewall/Router','10/100 Mbs',8,'980.95','FVX538.jpg',''),(12,4,'DI-655 Xtreme N','Router','10/100/1000 Mbs',8,'289.95','DI-655.jpg',''),(13,4,'DI-804HV VPN','Router','10/100 Mbs',4,'211.95','DI-804HV.jpg',''),(14,4,'DVG-1402S VoIP','Switch/Firewall/Router','10/100 Mbs',4,'235.95','DVG-1402S.jpg',''),(15,4,'DFL-210 NetDefend','Router/Firewall','10/100 Mbs',5,'711.95','DFL-210.png','');
/*!40000 ALTER TABLE `router_models` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2008-10-07 20:43:48

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.