Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

php html form mysql

Posted on 2006-04-20
3
Medium Priority
?
269 Views
Last Modified: 2009-12-16
Hello,

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.

Thanks,

K
0
Comment
Question by:t42ucsdedu
  • 2
3 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 16505018
Hello t42ucsdedu,

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

HTH

I
0
 
LVL 11

Expert Comment

by:neester
ID: 16512810
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" />
</form>
0
 
LVL 11

Accepted Solution

by:
neester earned 2000 total points
ID: 16512816
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:

unlink();

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
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…
Suggested Courses

571 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