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

Link to comment
Share on other sites

$_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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.