F
F
freeman02042016-10-24 14:59:43
PHP
freeman0204, 2016-10-24 14:59:43

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

1 answer(s)
R
romy4, 2016-10-24
@freeman0204

here in this 'users'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question