Jump to content

One Question to my solution (Image Upload)


nitation

Recommended Posts

Hello Guys,

 

I am uploading a file in php and everything seem working fine. A new request on the project was to upload the file into a folder on the server and the image name saved in MYSQL table. This as well is working alright. My question is, how do i insert multiple checkbox into my database.

 

Kindly see an instance;

 

checkbox      student

checkbox      family

checkbox      workplace

 

When a user click on the three checkboxes, how do i insert it to my database, capturing the value of each checkbox and inserting them in a new row.

 

Thanks

$_POST['student'] should equal "on" if it's selected.

 

You could do the following:

 

$fields = array ("student", "family", "work");

$add_to_db = array ();

foreach ($fields as $field)

{

  if (isset ($_POST[$field]) && $_POST[$field] == "on")

  {

    $add_to_db[] = $field;

  }

}

$fields_to_add_to_db = implode (",", $add_to_db);

 

or something like that...not very elegant

 

In my situation, the value for each check box is retrieved from my database. How do i use it in my array.

 

See this.

 

if each checkbox value =$categoryID

 

that means my html would be like this.

 

<input name=$categoryID type=checkbox value=$categoryID>

 

What do i do. The family, student and work are coming from my database. That means there are unlimited checkboxes that would be available. Hope this is clear

 

Thanks in advance

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.