Jump to content

Issue in Self Options adding of Question..


ArkeologeN

Recommended Posts

plz help me

in php

i want that

when a user clicks on add click

a new box will be appeared for question

consider

user is doing work with questions and options

he first gives a question

after it he clicks on ADD button

so a input box will appear

den he clicks again to ADD button

den aggain new box appears

at last

he clicks save then

they would be inserted into database

reply mee.. plz

do you have any code

or you want us to

write it for you?

it can be easily

done in Javascript

 

the form

place it within the <body> section of your document

<form method="post">
     <div>
          <input type="text" name="question[]" />
     </div>
     <button type="button" id="add">Add Question</button>
     <button type="submit" name="submit">Submit</button>
</form>

 

javascript code (with the jQuery library)

place it in the <head> section of your document

$(document).ready(function(){
     $('#add').click(function(){
          $('form div').append('<input type="text" name="question[]" />');
     });
});

 

php code to process the form

place it within the <body> section

if (isset($_POST['submit'])) {
     //this will return an array holding all the values of the inputs
     $questions = $_POST['question'];
     foreach ($questions as $question) {
           $results = mysql_query("INSERT INTO questions (question) VALUES ('$question')");
     }
     echo 'Your questions were added and will be responded soon. Bye!';
}

 

test the code and modify it

to your needs

you will need to add some

error handling to the php code

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.