<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>
$(document).ready(function() {
fetchUser();
function fetchUser() {
var action = "select";
$.ajax({
url: "include/project/select.php",
method: "POST",
data: {
action: action
},
success: function(data) {
$('#image').val('');
$('#title').val('');
$('#tags').val('');
$('#description').val('');
$('#action').text("Add");
$('#result').html(data);
}
});
}
$('#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");
}
});
});
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 'Помилка';
}
}
}
}
Ошибки не выдает, но и в базу не добавляет.
В чем может быть проблема?
Есть идентичный код но только с двумя полями ввода и там все прекрасно работает