Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Mal

macrumors 603
Original poster
Jan 6, 2002
6,252
18
Orlando
I need a way to implement a relatively simple checklist for items that are needed as donations. Basically, I want to list the items (doesn't need to be dynamic), and then let people check them off and place their name and email address in a database (email address should definitely not be publicly available, but I want an indication that someone has decided to bring that item). I'm a novice but not completely unfamiliar with PHP and MySQL, though that may be a bit overkill for this.

Anyone that can provide help will be thanked gratuitously.

jW
 

Cerebrus' Maw

macrumors 6502
Mar 9, 2008
409
1
Brisbane, Australia
In PHP, if you submit a HTML form that has got checkboxes to a script, the script can check if the boxes are 'turned on' If your checkbox does not exist in the $_POST array, that means that the check box was not ticked. So you know the checkboxes each time, you can check these elements, and if there are turned on, added it to this persons record. Psuedo code:

Code:
<form submit to php script>
Html form with 3 checkboxes, email address, and name
</form>


submits to php:

create record with customer name and email.

Check each boxes in $_POST array, if turned on(exists, isset) update this persons record.
If your comfortable, you could probably do this in one SQL statement but feel free to do it however.
 

Mal

macrumors 603
Original poster
Jan 6, 2002
6,252
18
Orlando
Sorry, maybe I was a little optimistic. I'm semi-decent at PHP, but the MySQL code I've barely dabbled in. I have trouble connecting to a database, much less actually checking records or editing them.

jW
 

Cerebrus' Maw

macrumors 6502
Mar 9, 2008
409
1
Brisbane, Australia
Ah, my bad.

Ok, I'm going to assume that you have a field in your table to represent each checkbox item, and these fields are by default set to false, null, empty etc. And that you have been able to connect to your Database and set up your tables. If your having problems at that stage, post what errors/problems your having, and we'll see if we can help with that.

First up, check the customer and see if their email exists. If it does, update the record, else insert a new one.

Code:
//Get the 
$cust_Email = $_POST['customer_Email'];
$cust_Name = $_POST['customer_Name'];

$chk_Cust = "select customer_Email from my_table where customer_Email='$cust_Email' ";
$chk_Res = mysql_query($chk_Cust);
//If the record does not exists, we have to insert it.
if(mysql_num_rows($chk_res)<=0)
{
      $ins_Cust = "insert into my_table set customer_Name='$cust_Name', customer_Email='$cust_Email' ";
      mysql_query($ins_Cust);
}


//Now check those boxes....
if (isset($_POST['food']) )
{
     $upd_Cust = "update my_table set food='Yes' where customer_Email='$cust_email' "; 
     mysql_query($upd_Cust);
}


//rinse and repeat...
if (isset($_POST['clothes']) )
{
     $upd_Cust = "update my_table set clothes='Yes' where customer_Email='$cust_email' "; 
     mysql_query($upd_Cust);
}

That's pretty basic, and you could probably use fewer SQL statements if you were clever with string concatenation when checking the boxes, but you get the idea...
 

Mal

macrumors 603
Original poster
Jan 6, 2002
6,252
18
Orlando
OK, that's still beyond what I've done previously, but I'm gonna give it a go and report back. It'll probably be a while, I won't get to work on it till this evening.

jW
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.