Jump to content

Creating an online shop


Guest Tim_C
 Share

Recommended Posts

Guest Tim_C

Hi folks,Apologies if I've either been too stupid when reading through the php tutorials or have missed something deceptively simple, but I'm attempting to create an online shop for my friend. However, unlike most normal online shops, where you purchase a single item, each item is unique and is buyer-created.Let me explain further... The buyer selects the first option 'colour of band'. They then have to select 'braid type', 'length of braids', and 'extra braids?'. All of these have associated cost, and also affects the P&P of the final package. Not only that, the buyer can create up to 5 items at once (would it be possible to create an infinite number?).The buyer selects all of these options using radio buttons presented in a tablulated form, like so:Page 1Band 1 - Colour (4 options) - Braid Type (9 options) - Length (6 options) - Extra Braids (4 options)Band 2 - Colour (4 options) - Braid Type (9 options) - Length (6 options) - Extra Braids (4 options)Band 3 - Colour (4 options) - Braid Type (9 options) - Length (6 options) - Extra Braids (4 options)Band 4 - Colour (4 options) - Braid Type (9 options) - Length (6 options) - Extra Braids (4 options)Band 5 - Colour (4 options) - Braid Type (9 options) - Length (6 options) - Extra Braids (4 options)The user then presses 'Submit' and gets a new page, which tells them:Page 2Band 1 is 'colour', has 'Braid Type' braids. The braids are 'length', and there are 'Extra Braids' extra braids. This will cost 'total cost' GBP.Band 2 is... etcNow, to use the data collected on Page 1 and get it to Page 2, I use a $_POST query, as Page 1 is a tabulated form. However, if nothing is selected, how do I ensure that Page 2 does not show any unselected Bands, i.e. Page 2 doesn't look like:Band 1 is black, has simple braids. The braids are short, and there are 0 extra Braids. This will cost 25 GBP.Band 2 is 'Colour', has 'Type' braids. The braids are 'Length', and there are 'Extra' extra braids. This will cost 'total cost' GBP.Could I use an If...Else statement? So if the 'colour' option is not selected the POST page will not show that line at all?And would it be worth my while setting up a MySGL database for all of this?Alternatively, is there a 'php for Dummies' that I can look through? I can create html pages easily, and understand javascripting, but php seems to be doing my head in...Apologies if this is just too easy or something that I should be experimenting with until I get a good answer, but I'm starting to lose it a bit... :) Tim

Link to comment
Share on other sites

Don't worry about it. This is easy enough to solve. On Page 2, before ANY other code you would put

<?phpif ($_POST['braid2_colour'] == "Colour") {  header("Location: Page1");}?>

Of course you would add in additional fields for each of the additional braid fields. However, this will redirect them even if they select 1 band and then in the final box select 0 extra bands. You can solve this with.

<?phpif ($_POST['braid1_additional'] != "0") etc. etc. etc. etc.{  if ($_POST['braid2_colour'] == "Colour") {	header("Location: Page1");}?>

Link to comment
Share on other sites

Sorry I can't help you as much with the code at the moment, but here's some tips that you might find usefull:Use an loop to put how many rows/bands you want. You can create a form with just a select-box (maybe a "go-button", if you don't wnat to use onchange="document.form[0].submit()" on the select) that let's the buyer select how many band she/he wants to order, then put that many "rows" using the loop:

for ($I = 0;$I < $num_of_bands; $I++) { /// The row.. ?><tr>	<td>Band <?php echo $I+1 ?></td>   <td><input type="radio" name="colour[]" /></td>...</tr><?php}

Note the square brackets in the name, you don't wan't to set a default value (checked="checked") as this will stop the rest to work as intended.On page 2 you get each "field" (colour etc) as arrays in $_POST (you can use print_r($_POST); if you wnat a better "view"):

$colour_arr = $_POST['colour'];...

Just loop thru the color array, using for (not foreach) (as there should be as many in the other arrays, you can use the same "index").The one's without a value wont be send to the server.All this means that you can have any number of bands (from 1 to 100 and upwards...)How to you plan to save the order without an db? A db would simplify handling of the data about the customer and the orders, billing and which order has been sent to the buyer etc...Hope that helped!Good Luck and Don't Panic!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...