I do not understand where I am wrong. You have an error in your SQL syntax; check it out.
$result = mysql_query("INSERT INTO 'persons' VALUES ($idInput, $nameInput, $lnameInput, $ageInput)" , $db) or die(mysql_error());
I do not understand where I am wrong. You have an error in your SQL syntax; check it out.
$result = mysql_query("INSERT INTO 'persons' VALUES ($idInput, $nameInput, $lnameInput, $ageInput)" , $db) or die(mysql_error());
quotes around string values who will put? and put MySQL Workbench, it automatically highlights the line with incorrect syntax, and debug your queries
ps and you have another error (the root cause, by the way) - single quotes around the table name
mysql> use 'db'; #здесь корректно, но излишне, это внутренняя команда mysql # хотя use db тоже сработает (и быстрее печатать) Database changed mysql> show tables; +--------------+ | Tables_in_db | +--------------+ | OrderHistory | | users | +--------------+ 2 rows in set (0.00 sec) #здесь некорректно, не по стандарту SQL mysql> select * from 'users'; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''users'' at line 1
firstly, in this query, quotes around the table name are not needed, and secondly, the correct quotes for sql are backticks:
mysql> select * from `users`; +----+------------+- | id | login
The answer to the comments regarding quotes around INT / DOUBLE / FLOAT type fields, etc .: they are possible, but not necessary. With a small load, the extra baytik spent on transferring quotes is imperceptible.
With a large load, when inserting large amounts of data (when you insert data up to max_allowed_packet
), when you have a lot of numeric fields, you will receive an additional load / have to reduce the number of rows that you can insert simultaneously.
In addition, purely semantically, it makes it clear when you look at any big query that the numbers should be inserted into a column with a numeric type.
When you see such a request, you understand that there is logic and intention in it.
Source: https://ru.stackoverflow.com/questions/543517/
All Articles
"INSERT INTO persons VALUES ('$idInput', '$nameInput', '$lnameInput', '$ageInput')"
- Mr. Black