N
N
night_amir2011-08-24 15:45:18
PHP
night_amir, 2011-08-24 15:45:18

Auto increment field in MySQL database

I try to execute request:
$sql_add = "INSERT INTO CHAT_MSG VALUES ('', ".$forum_user_id.", '".$msg."', '1', ".intval(time()).", '".$priv."')";

The first field autoincrement. It used to roll like that. When inserting a row, the value was incremented by 1 and the row was inserted. After moving to the screw server it ceased to work.

Tell me how to solve?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
night_amir, 2011-08-24
@night_amir

It was necessary to pass null to the auto-increment field.
Esin, thanks for your reply! :)

A
Andrew, 2011-08-24
@Morfi

I prefer the syntax

INSERT INTO
    table_name
SET
    field1 = "val1",
    field2 = "val2"

E
esin, 2011-08-24
@esin

Try to specify the fields of the table into which values ​​are entered during insertion (if this is an auto-increment field, do not specify).
For example, let field0 be an auto-increment field in the table table
INSERT INTO TABLE(field1, field2, fileld3) VALUES (value1, value2, value3);

X
Xenkok, 2011-08-29
@Xenkok

Also, there is one more rule - optional, but it should be followed in order to avoid errors:
Field and table names should be enclosed in back single quotes - "`" (the key with this symbol is located on the standard keyboard to the left of the "1" key) After all the field name can match mysql keywords, but if we use a back quote, then MySQL will understand everything correctly:
SELECT * FROM `table` WHERE `date` = '2006-04-04'
the site phpfaq.ru
is a word.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question