php html form mysql

Posted on 2006-04-20
Last Modified: 2009-12-16

I have 5 files stored in a dir /upload i.e file1, file2...)

These five file information are stored in a mysql database as shown below:

title      cat1    cat2    cat3
file1     on       off      on      //'on' means a file can belong to more than one category
file 2   off        on      on

I would like to have a form that as shown below:

title      cat1                     cat2                    cat3                 delete
file1     checkbox           checkbox          checkbox       checkbox
file2    checkbox            checkbox          checkbox       checkbox
- A user should be able to either check cat1's checkbox or all of the cat checkboxes at the same to update their status in the db.  Also, he or she should be able check the 'delete' checkbox (not selecting other checkboxes) and delete this file from the /upload dir.

Please provide simple code please.


Question by:t42ucsdedu
    LVL 22

    Expert Comment

    by:Ivo Stoykov
    Hello t42ucsdedu,

    please quote your script to see what's the problem.


    LVL 11

    Expert Comment

    ExpertsExchange isnt a free coding area.

    You are meant to have a problem that we can fix for you.
    Try it out yourself, if you are stuck, ask what to do next.

    To help you out here is a tiny example of what you might want:

    if ($_POST['submit']) {

    for ($i=1;$i<=5;$i++) {

       $changeInfo[] = ($_POST['cat1']['file'.$i] == 'on')?"cat1='on'":"cat1='off'";
       $changeInfo[] = ($_POST['cat2']['file'.$i] == 'on')?"cat2='on'":"cat2='off'";
       $changeInfo[] = ($_POST['cat3']['file'.$i] == 'on')?"cat3='on'":"cat3='off'";

       $updateStr=implode(",", $changeInfo);

       mysql_query("UPDATE fileinfo SET $updateStr WHERE filename='{$_POST['title'][$i]}'");

    <form method="post">
    <input name="title[1]" type="hidden" value="file1" /> <input name="cat1[1]" type="text" value="on" />|<input name="cat2[1]" type="text" value="on" />|<input name="cat3[1]" type="text" value="on" /><br />
    <input name="title[2]" type="hidden" value="file1" /> <input name="cat1[2]" type="text" value="on" />|<input name="cat2[2]" type="text" value="on" />|<input name="cat3[2]" type="text" value="on" /><br />
    <input name="title[3]" type="hidden" value="file1" /> <input name="cat1[3]" type="text" value="on" />|<input name="cat2[3]" type="text" value="on" />|<input name="cat3[3]" type="text" value="on" /><br />
    <input name="title[4]" type="hidden" value="file1" /> <input name="cat1[4]" type="text" value="on" />|<input name="cat2[4]" type="text" value="on" />|<input name="cat3[4]" type="text" value="on" /><br />
    <input name="title[5]" type="hidden" value="file1" /> <input name="cat1[5]" type="text" value="on" />|<input name="cat2[5]" type="text" value="on" />|<input name="cat3[5]" type="text" value="on" /><br />
    <br /><br />
    <input name="submit" type="submit" value="SUBMIT" />
    LVL 11

    Accepted Solution

    It is very ugly and may not work properly.
    But it is a start.

    I used textboxes and not dropdowns or options.
    You can update that im sure.

    I left DELETE off the script.
    You can add that similar to the other values.

    To delete a file in PHP, you need to use this function:


    However you also need to make sure you have permission to delete the file. (apache will need to be the file owner)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now