0

I have a form on my site for adding data to the database. If the form has two inputs, everything works. Now I have added four forms and records are no longer added to the database. What could be the error?

Form:

<form action="">
    <input type="text" placeholder="Image Link" class="input_to_name" name="image" id="image"><br>
    <input type="text" placeholder="Project Name" class="input_to_name" name="title" id="title"><br>
    <input type="text" placeholder="Tags" class="input_to_name" name="tags" id="tags"><br>
    <textarea name="description" id="description" cols="30" rows="10" placeholder="Opisz project" class="textarea_for_desciprion"></textarea><br>
    <div>
    <input type="hidden" name="id" id="user_id" />
    <button type="button" name="action" id="action" class="publish_job"></button>
    </div>
    </form>

I use the script to pass data to the 'action' file:

 $(document).ready(function() {
                $('#action').click(function() {
                    var Image = $('#image').val();
                    var Title = $('#title').val();
                    var Tags = $('#tags').val();
                    var Description = $('#description').val();
                    var id = $('#user_id').val();
                    var action = $('#action').text();
                    if (Image != '' && Title != '' && Tags != '' && Description != '') {
                        $.ajax({
                            url: "include/project/action.php",
                            method: "POST",
                            data: {
                                Image: Image,
                                Title: Title,
                                Tags: Tags,
                                Description: Description,
                                id: id,
                                action: action
                            },
                            success: function(data) {
                                alert(data);
                                fetchUser();
                            }
                        });
                    } else {
                        alert("Both Fields are Required");
                    }
                });
    });

And this is PHP code that is used to add data to the database

if (isset($_POST["action"])) {
         $output = '';
         $connect = mysqli_connect("localhost", "root", "", "brandbackup");
         if ($_POST["action"] == "Add") {
              $image = mysqli_real_escape_string($connect, $_POST["Image"]);
              $tags = mysqli_real_escape_string($connect, $_POST["Tags"]);
              $title = mysqli_real_escape_string($connect, $_POST["Title"]);
              $description = mysqli_real_escape_string($connect, $_POST["Description"]);
              $procedure = "  
              CREATE PROCEDURE insertUser(IN Image varchar(250), Tags varchar(250), Title varchar(250), Description varchar(250))
              BEGIN  
              INSERT INTO projects(image, tags, title,description) VALUES (Image, Tags, Title, Description);   
              END; 
               ";
              if (mysqli_query($connect, "DROP PROCEDURE IF EXISTS insertUser")) {
                   if (mysqli_query($connect, $procedure)) {
                        $query = "CALL insertUser('" . $image . "', '" . $tags . "',  '" . $title . "', '" . $description . "')";
                        mysqli_query($connect, $query);
                        echo 'Data Inserted';
                   } else {
                        echo 'Error';
                   }
              }
         }
    }
Patso
  • 1

0 Answers0