Checklist for tracking donated items?

Discussion in 'Web Design and Development' started by Mal, Aug 26, 2009.

  1. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #1
    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
     
  2. Cerebrus' Maw macrumors 6502

    Joined:
    Mar 9, 2008
    Location:
    Brisbane, Australia
    #2
    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.
     
  3. Mal thread starter macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #3
    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
     
  4. Cerebrus' Maw macrumors 6502

    Joined:
    Mar 9, 2008
    Location:
    Brisbane, Australia
    #4
    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...
     
  5. Mal thread starter macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #5
    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
     

Share This Page