ArkeologeN Posted May 30, 2011 Share Posted May 30, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/237845-issue-in-self-options-adding-of-question/ Share on other sites More sharing options...
Fadion Posted May 30, 2011 Share Posted May 30, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/237845-issue-in-self-options-adding-of-question/#findComment-1222222 Share on other sites More sharing options...
spiderwell Posted May 30, 2011 Share Posted May 30, 2011 this sounds fasinating, perhaps you can share the code that you have already and we can then point you in the right direction. from your description it sounds like javascript will be involved to produce dynamic changes to the form. Quote Link to comment https://forums.phpfreaks.com/topic/237845-issue-in-self-options-adding-of-question/#findComment-1222223 Share on other sites More sharing options...
ArkeologeN Posted May 30, 2011 Author Share Posted May 30, 2011 Error Here if (isset($_POST['submit'])) { $questions = $_POST['qstn']; foreach ($questions as $question) { $result = mysql_query("INSERT into $table1 question VALUES ('$question')"); } echo "Question Successfully Added!"; } Quote Link to comment https://forums.phpfreaks.com/topic/237845-issue-in-self-options-adding-of-question/#findComment-1222233 Share on other sites More sharing options...
Fadion Posted May 30, 2011 Share Posted May 30, 2011 That query makes no sense. What is the table structure? What value are you passing to $table1? Quote Link to comment https://forums.phpfreaks.com/topic/237845-issue-in-self-options-adding-of-question/#findComment-1222243 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.