Jump to content
  • 0

Ошибка БД


T@NKIST
 Share

Question

Вот php код:

$mysql = mysql_connect('localhost','abc','def');
mysql_select_db('db',$mysql);
if(mysql_query('INSERT INTO video (name,html,about,date) VALUES('.$name.', '.$html.', '.$about.', '.$date.')')){

вот код ошибки:

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 '.2011)' at line 1a,b,c,20.11.2011

что я сделал не правильно?

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Попробуй взять video в кавычки:

if(mysql_query('INSERT INTO `video` (name,html,about,date) VALUES('.$name.', '.$html.', '.$about.', '.$date.')')){

P.S.: Если не поможет, тогда ещё попробуй убрать конкатенацию запятых:

if(mysql_query("INSERT INTO video (name,html,about,date) VALUES('$name', '$html', '$about', '$date')")){

или так:

if(mysql_query("INSERT INTO  `video` (name,html,about,date) VALUES('$name', '$html', '$about', '$date')")){

Edited by DrStrangeLove
Link to comment
Share on other sites

  • 0

а не проще было записать так:


if(mysql_query
("INSERT `pages` SET
`id` = '".$_GET['id']."',
`name` = '$name',
`html` = '$html',
`about` = '$about',
`date` = '$date'")
);

?

UPD: не забываем про sql инъекцию и добавляем проверку для $id mysql_real_escape_string, а еще лучше убрать строчку:

`id` = '".$_GET['id']."',

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy