0

Below is an explanation of exactly what I want

On the submission form I have multiple checkboxs. when users click on checkbox a textbox appears next to it, where user input text. I want to insert the value of texbox in array and insert it in database with PHP-MYSQL. for example checkbox1 is index 0=>valueoftextbox, checkbox2 is index 1=>value of texbox2

How can I achieve this?

1

2 Answers 2

0

Serialize received $_POST.

<input type="checkbox" name="smth[]" value="One" />
<input type="checkbox" name="smth[]" value="Two" />
<input type="checkbox" name="smth[]" value="Three" />

<?php
if (isset($_POST)) {
   $smth = serialize($_POST['smth']);
   $query = mysql_query("INSERT INTO table VALUES ('$smth')") or die(mysql_error());
}
0

A few pointer to get you going:

1) From PHP use:

echo "<pre>";
print_r($_POST);
echo "</pre>";

That way you can see WHAT is posted from your client-form.

2) Note that an unchecked checkbox ISN'T posted at all.

So if you have following checkbox in your form named "wantsnewsletter".

Then check that from PHP like this:

 if (isset($_POST["wantsnewsletter"])){
   // It was checked.
 } else {
   // It wasn't checked
 }

Futhermore you just have to think up some sensible naming and do the inserts into you DB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.