Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- $(document).ready(function() {
- $('body').on('click', '.save', function(e) {
- var string = $(this).serialize();
- $.ajax({
- type: "POST",
- url: "add_room.php",
- data: string,
- cache: false,
- success: function(data){
- $('#message').text('The id of the inserted information is ' + data);
- }
- });
- });
- });
- $(document).ready(function(){
- $('#addForm').on('click', function(){
- $('<label for="itemName[]">Item</label><input class="itemName" type="text" name="itemName[]"><label for="itemCondition">Condition</label><input class="itemCondition" type="text" name="itemCondition"><div class="save">Save Item</div>').fadeIn(500).appendTo('#mainForm');
- });
- });
- </script>
- <?PHP
- include('dbConfig.php');
- $item = $db->real_escape_string($_POST['itemName']);
- if ($stmt = $db->prepare("INSERT test (test_title) VALUES (?)"))
- {
- // Use an s per variable passed to the string, example - "ss", $firstname, $lastname
- $stmt->bind_param("s", $item);
- $stmt->execute();
- $stmt->close();
- echo $db->insert_id;
- //echo "success";
- }
- // show an error if the query has an error
- else
- {
- echo "ERROR: Could not prepare SQL statement.";
- }
- ?>
- var string = $(this).closest('form').serialize();
- var string = $('#input1,#nextone,#somefield').serialize();
- var string = $(this).serialize();
- $_POST['itemName']
- <form method="POST" class="save" action="add_room.php">
- <input type="text" name="itemName[]"/>
- <input type="text" name="itemName[]"/>
- <button type="submit">Save</button>
- </form>
- $(document).on("submit",".save",function(e){
- e.preventDefault();
- $.post($(this).attr("action"),$(this).serialize(),function(r){
- //result
- alert(r);
- });
- });
- $item = $_POST['itemName']
- foreach( $item as $key => $val ) {
- //iterate itemName values
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement