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

Link to comment
Share on other sites

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

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.