Yohanne Posted March 25, 2014 Share Posted March 25, 2014 Hi coders, i create Dynamically input fields, kindly assist, what going wrong with this.. the problem is cannot save. please.. <html> <head> <title> Dynamically create input fields </title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script type="text/javascript"> $(function() { var addDiv = $('#addinput'); var i = $('#addinput p').size() + 1; $('#addNew').live('click', function() { $('<p><input type="text" id="p_new" size="20" name="p_new_' + i +'" value="" placeholder="I am New" /><a href="#" id="remNew">Remove</a> </p>').appendTo(addDiv); i++; return false; }); $('#remNew').live('click', function() { if( i > 2 ) { $(this).parents('p').remove(); i--; } return false; }); }); </script> </head> <body> <div id="addinput"> <?php require_once 'database/connection.php'; $DBcon = new connection(); ?> <p> <form name ="form" action = "" method = "POST"> <input type="text" id="p_new" size="20" name="p_dnew" value="" placeholder="Input Value" /><a href="#" id="addNew">Add</a> <input type="submit" size="20" name="Save" value="Save"/> </form> </p> <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { $p_dnew = implode(',',($_POST['p_dnew']); $query = ("INSERT INTO branch(brach_name) VALUES('{$p_dnew}')"); $result = mysql_query($query); } else { return false; } ?> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/287246-dynamically-create-input-fields-and-insert-after-submit/ Share on other sites More sharing options...
ginerjm Posted March 25, 2014 Share Posted March 25, 2014 I don't get the use of the implode function on an input of 1 value. All this is going to do is put a comma(?) after that value and then you will pass that to the query. If you had used a test on the query results you would have probably been shown a mysqli error message saying your query is bad. Link to comment https://forums.phpfreaks.com/topic/287246-dynamically-create-input-fields-and-insert-after-submit/#findComment-1473779 Share on other sites More sharing options...
Yohanne Posted March 25, 2014 Author Share Posted March 25, 2014 okay,, thanks but may i see your solution? Link to comment https://forums.phpfreaks.com/topic/287246-dynamically-create-input-fields-and-insert-after-submit/#findComment-1473782 Share on other sites More sharing options...
ginerjm Posted March 25, 2014 Share Posted March 25, 2014 My solution? I'm only pointing out what I see as a potential pitfall. It's up to you to either clarify what I'm seeing perhaps incorrectly, or to produce your own corrections. Link to comment https://forums.phpfreaks.com/topic/287246-dynamically-create-input-fields-and-insert-after-submit/#findComment-1473784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.