Answer the question
In order to leave comments, you need to log in
Why is it not possible to write to the database here?
My validation is 'Error'/ Is there something wrong with the INSERT INTO query?
<form action="" class="calc">
<input type="text" name="name" placeholder="Имя">
<input type="text" name="price" placeholder="Цена">
<input type="text" name="url" placeholder="URL(картинки)">
<textarea name="text" name="description" placeholder="Описание"></textarea>
<input type="submit" id="send" value="Отправить">
</form>
$db = mysql_connect('localhost', 'calc', '');
mysql_select_db('calc');
mysql_query('SET NAMES utf8');
$ret = true;
mysql_query("INSERT INTO 'users' (name, price, url, description) VALUES ('" . $_POST['name'] . "', '" . $_POST['price'] . "', '" . $_POST['url'] . "', '" . $_POST['description'] . "')") or $ret = false;
echo $ret;
</code
<code lang="javascript">
$("#send").click(function() {
var dannie = $("form").serialize();
$.ajax({
url: '/insert.php', // путь к файлу скрипта
type: 'POST',
data: dannie, //передача данных
success: function(data) {
if(data) {
alert("Новость вставлена");
} else {
alert("Ошибка");
}
} //условие success на котором сработает функция data
})
});
</code>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question