I am trying to make an online ordering system for our shop using HTML, php and mysql. We need to send the customers a confirmation email. I am using the simple mail() function. The first part of the message comes through just fine, but not the actual product (there are actually about 150 "hats" and I do not want to send the customer a long mail with 149 things that he has not ordered). Here is the code - what am I doing wrong? Any hints greatly appreciated!

<?php
$to = "{$_POST['email']}";
$subject = "Order No. {$result["mysql_insert_id"]}";
$message = "Thank you for your Order.\n
Your order number is {$result["mysql_insert_id"]} (you will need to provide this number when you collect the order).\n
Your order was taken by {$_POST['takenBy']} on {$_POST['orderDate']} \n
{$_POST['name']} {$_POST['surname']} \n
{$_POST['email']} \n
Tel. {$_POST['telephone']} \n
Your order will be ready to collect from {$_POST['takenAt']} on {$_POST['collectDate']} \n
Deposit Paid: £{$_POST['deposit']}\n";

Show us your actual form, or the URL to the form on your website.
Your form will contain variable arrays, not individual names for each variable.
This will simplify it for you immensely.

oddshoes

11-19-2012, 10:42 PM

I fear I am altogether on the wrong path - this is the first interactive thing I've tried. Here is the code for the input page - sorry it's huge! I took a load of the JS out in the middle to make it fit.

So you can do various queries ...
find all rows with the category 'ham'. or 'pork', or 'chicken'
find all rows with the type 'ham cooked', or 'ham sliced'

As you do queries and build the HTML form 'dynamically', each
value of checkbox is the 'unique id' number of the row.
If you add or delete rows, those unique id' numbers are never
repeated nor are they ever used again.

Example: if one of my checkboxes is 125, I know that they selected the ham item HC100.

You need to get the database organized and determine the scheme of how you
wish to lay it out. You also need another database table for the users?

So, start with getting the database done correctly and go from there.

.

oddshoes

11-20-2012, 12:10 AM

I have a MySQL database with two tables - orders and users. Users is simple, just the names and p/w of the people who can log in and place orders. Orders is more complicated, it is: unique row id (orderNo)then 10 fields of customer info including | collectDate | followed by 140 fields labled | qty12 | qty13 | qty14 | etc. I used qty12 etc. rather than the actual product name as the products change quite a lot with the seasons and we would be continually adding columns to the DB - which might in retrospect have been a better solution. We query the DB to find eg. SUM(qty12) WHERE collectDate = 2012-11-22 and also SELECT * WHERE orderNo = xyz to print a copy for the staff to pick the order. This all works fine. My problem is that to construct the confirmation mail I need to get the non 0 values out of the post array and turn qty12 into smoked cooked ham (for example) and put this info into $message for the mail.

mlseim

11-20-2012, 01:00 AM

oh my.

Do you see why one row for EACH product would be a better way to do this?

You add a row when you add a new product.
You delete a row (or have a field called 'enable') when you remove a product.
Add a column called 'season' if you wish to associate a product with a season.

It is great that you're diving into PHP/MySQL though ... I'll give you points for that.
You'll learn a lot by making mistakes and asking questions. You'll just have to
either trust me on my advice to start over, or keep plowing ahead and see where
you end up.

I won't even attempt to try coding a script example that you desire. Sorry, but
your method is just too wrong. I really suggest you hire a freelance programmer
to assist you.

My goal is for you to keep at it ... I don't want to discourage you.

.

oddshoes

11-21-2012, 02:40 PM

Thanks for your advice - I know I'm out of my depth, but I learn faster when it's for "real". I managed to resolve the question with some inelegant php contortions, so the system works for now. I will keep it on line 'till Christmas as it is a considerable advance on last years model - faxing and copying bits of paper and hand entering into a spreadsheet! After that I will take it off line and completely redesign it in light of the experience gained.
Out of interest, how does one go about getting freelance help?
cheers

mlseim

11-21-2012, 03:58 PM

There is a section on this forum called "Web Projects", where you can
request programming help (hire a freelancer). Show them this thread
and explain your requirements.

I've never experienced using that part of the forum, so I can't tell you
how well it will work. There are experienced programmers all over the
world, so you just want to make sure that the person you hire speaks
your native language fluently. Communication with emails, phone calls,
etc. depends on understanding each other.

You also need to trust the person ... as they will need full access to your
website, your MySQL database, your FTP ... all files. With your webhost
control panel, you can create separate logins for other people. Perhaps
the freelancer should be given their own FTP login, and you should create
a new MySQL database for them to use?