473,503 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creating product catagories

AaronL
99 New Member
Hello,

I am developing an e-commerce system and I want to be able to create catagories and subcatagories for items. I have the basics down however I may be making things too complicated. First I select a parent catagory and the page sucessfully brings me to the subcatagory screen, however anything past that, the catagory id variable is not being passed back to the application. Here is the code, hopefully someone can understand what I'm trying to do and figure out what's wrong, my brain is about to explode. Thanks again!

Expand|Select|Wrap|Line Numbers
  1. $catid = $_POST['catid'];
  2. $catdesc = $_POST['catdesc'];
  3. echo "<h1>Catagory ID: " . $catid . "</h1>";
  4. if ($catid == '') 
  5. {
  6.   $buildsql = "SELECT * FROM catagories WHERE parent=0";
  7.   $result = mysql_query($buildsql);
  8.   $numrows = mysql_num_rows($result);
  9.   if($numrows <= 0)
  10.   {
  11.     echo "<h1>There are no catagories!</h1>";
  12.   }
  13.   echo "<br><br><form action='catagory.php' method='post'><table align='center' border='1'><tr><td bgcolor='#C0C0C0' align='center'><b>Select Parent Catagory</b></td></tr>";
  14.   echo "<tr><td align='center'><select size='10' name='catid'>";
  15.   while($rowset = mysql_fetch_array($result))
  16.   {
  17.     echo "<option id=" . $rowset[catid] . " value=" . $rowset[catid] . ">" . $rowset[description] . "</option>";
  18.   }
  19.   echo "</select><br><p align='right'><input type='submit' value='Next ->' /></p></td></tr></form></table>";
  20. }
  21. else
  22. {
  23.   //find sub-catagories
  24.   $buildsql = "SELECT * FROM catagories WHERE catid=" . $catid;
  25.   $result = mysql_query($buildsql);
  26.   $rowset = mysql_fetch_array($result);
  27.   $catdesc = $catdesc + $rowset[description] . " ->";
  28.   $buildsql = "SELECT * FROM catagories WHERE parent=" . $catid;
  29.   $result = mysql_query($buildsql);
  30.   $numrows = mysql_num_rows($result);
  31.   If($numrows <= 0)
  32.   {
  33.     echo "<h1>code your submit catagory here!</h1>";
  34.   }
  35.   else
  36.   {
  37.     echo "<br><br><form action='catagory.php' method='post'><table align='center' border='1'><tr><td bgcolor='#C0C0C0' align='center'><b>Select Sub-Catagory</b></td></tr>";
  38.     echo "<tr><td align='center'><select size='10' name='catid'>";
  39.     while($rowset = mysql_fetch_array($result))
  40.     {
  41.       echo "<option id=" . $rowset[catid] . " value=" . $rowset[catid] . ">" . $rowset[description] . "</option>";
  42.     }
  43.   echo "</select><br><p align='right'><input type='submit' value='Next ->' /></p></td></tr></form></table>";
  44.   }
  45. }
  46. mysql_close($con);
  47.  
My code is easy to laugh at considering I'm quite a newbie but no offence taken LOL!
May 13 '09 #1
4 1618
AaronL
99 New Member
Oh yeah, here is the URL to show you what is happening

http://www.lambertsoftware.com/ecomm/catagory.php
May 13 '09 #2
prabirchoudhury
162 New Member
hey
you do have couple of bad practice on declaring variables and spelling


solution

Expand|Select|Wrap|Line Numbers
  1. $catid = $_POST['catid']; 
  2. $catdesc = $_POST['catdesc']; 
  3.  
  4. //call the function
  5. find_category($catid);
  6.  
  7. function find_category($catid){
  8.     echo "<h1>Catagory ID: " . $catid . "</h1>"; 
  9. if ($catid == '')  
  10.   $buildsql = "SELECT * FROM catagories WHERE parent=0"; 
  11.   //echo $buildsql;
  12.   $result = mysql_query($buildsql); 
  13.   $numrows = mysql_num_rows($result); 
  14.   if(!$numrows > 0) 
  15.   { 
  16.     echo "<h1>There are no catagories!</h1>"; 
  17.   } 
  18.   echo "<br><br><form action='edit.php' method='post'><table align='center' border='1'><tr><td bgcolor='#C0C0C0' align='center'><b>Select Parent Catagory</b></td></tr>"; 
  19.   echo "<tr><td align='center'><select size='10' name='catid'>"; 
  20.   while($rowset = mysql_fetch_array($result)) 
  21.   { 
  22.     echo "<option id=" . $rowset[catid] . " value=" . $rowset[catid] . ">" . $rowset[description] . "</option>"; 
  23.   } 
  24.   echo "</select><br><p align='right'><input type='submit' value='Next ->' /></p></td></tr></form></table>"; 
  25. else 
  26.  
  27. //###you cant use same variables name for two different query before taking off the values.
  28.   //find sub-catagories 
  29.   $buildsql = "SELECT * FROM catagories WHERE catid=" . $catid; 
  30.   $result = mysql_query($buildsql); 
  31.   $rowset = mysql_fetch_array($result);
  32.  
  33.   $catdesc = $rowset[description] . " ->";
  34.   echo  $catdesc;
  35.  
  36.   $buildsql2 = "SELECT * FROM catagories WHERE parent=".$catid; 
  37.   $result2 = mysql_query($buildsql2);
  38.   echo "<br>". $buildsql2;
  39.   $numrows2 = mysql_num_rows($result2); 
  40.   If(!$numrows2 > 0) 
  41.   { 
  42.     echo "<h1>code your submit catagory here!</h1>"; 
  43.   } 
  44.   else 
  45.   { 
  46.     echo "<br><br><form action='catagory.php' method='post'><table align='center' border='1'><tr><td bgcolor='#C0C0C0' align='center'><b>Select Sub-Catagory</b></td></tr>"; 
  47.     echo "<tr><td align='center'><select size='10' name='catid'>"; 
  48.     while($rowset2 = mysql_fetch_array($result2)) 
  49.     { 
  50.       echo "<option id=" . $rowset2[catid] . " value=" . $rowset2[catid] . ">" . $rowset2[description] . "</option>"; 
  51.     } 
  52.   echo "</select><br><p align='right'><input type='submit' value='Next ->' /></p></td></tr></form></table>"; 
  53.   } 
  54. }
  55.  
  56. }
that shoud wrk fine ..
May 13 '09 #3
AaronL
99 New Member
Still has the same problem, I looked over everything as far as spelling with no problems, it has something to do with the form not posting correctly
May 13 '09 #4
AaronL
99 New Member
I resolved the problem, apparently the post method has some issues. I used method='get' in my form instead and got the result I wanted.
May 13 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2201
by: Andrea | last post by:
I'm having some difficulty creating a report in Access and I need some suggestions. My company issues "Return Authorizations" when customers need to return products. A customer calls in and we...
3
5856
by: SouthSpawn | last post by:
I am creating a web application. I would like to create a product key for the app that expires after a full year of usage. Any suggestions? Thanks, Mark
3
1878
by: Tony Johansson | last post by:
Hello!! We are using .NET C# so the product must use this language. The existing controls within .NET is not good enough so I'm looking and evaluating other products. We need a product to...
6
3869
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display my array of objects in a GUI. How do I get JLabel to refer to the data in my objects? I've read my textbook and some tutorials online I just cannot get this. Plus all the...
4
1430
Fary4u
by: Fary4u | last post by:
Hi every one any body can help me in this regards ? i don't know how to do that how do i convert following code into sub catagory ? like . . . Computer Mainboards Keyboards Mouse Process...
1
1037
Fary4u
by: Fary4u | last post by:
Hi every one any body can help me in this regards ? i don't know how to do that how do i convert following code into sub catagory ? like . . . Computer Mainboards Keyboards ...
22
2685
kcdoell
by: kcdoell | last post by:
I have been trying for the last several days to create a query that will give me all of the values I need to create a report. Background: The report is different than anything I have done but...
1
4213
AaronL
by: AaronL | last post by:
Hello, First I would like to say thank you all for your help in the past. I am stumped again. I am creating an e-commerce system and I want to be able to upload images to the server and...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.