php html form mysql


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.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ivo StoykovCommented:
Hello t42ucsdedu,

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


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" />
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)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.