开发者

my sql query doesn't insert anything, what am i doing wrong?

i'm trying to insert a query into a database, however for some reason it's not working, perhaps you guys can see something i don't.

i know the enrties is right (as the checking bit does work on another page and so does the db selection.

it's starting to drive me nuts by now, and so is my project mate.

the query is used in PHP, after having filled a form. (on a different page).

$insert_query = "INSERT INTO enrties(
datum,
naam Relatie,
ContactPersoon,
bezoekreden)
VALUES (
'$_开发者_运维百科SESSION[Datum]',
'$_SESSION[RelatieNaam]',
'$_SESSION[ContractPersoon]',
'$_SESSION[redenBezoek]')";

 mysql_query($insert_query);

my thanks in advance.

p.s: i'm using php my admin

EDIT: none of them did the trick, but i solved it because there was a , to much somewhere else >.<


naam Relatie is not a valid field name. Field names must be a single word, or escaped to "hide" the space. Beyond that, fieldnames with spaces in the name are bad practice, and as you can see, are VERY prone to causing just such problems.


$insert_query = "
INSERT INTO enrties
(`datum`,`naam Relatie`,`ContactPersoon`,`bezoekreden`)
VALUES ('$_SESSION[Datum]','$_SESSION[RelatieNaam]','$_SESSION[ContractPersoon]','$_SESSION[redenBezoek]')";

mysql_query($insert_query);

You should wrap field names in ` , and strings in '


mysql_error() will probably point you in the right direction as others have said.

Another point to note is that you shouldn't have array elements directly in your strings without enclosing them in curly braces, and field names with spaces in them should be enclosed in backticks.

My best guess for why it is failing though is that you have spelled the table name wrong. It should probably be "entries".

I would try this:

$insert_query = "INSERT INTO `entries` (`datum`,
`naam Relatie`,
`ContactPersoon`,
`bezoekreden`)
VALUES (
'{$_SESSION['Datum']}',
'{$_SESSION['RelatieNaam']}',
'{$_SESSION['ContractPersoon']}',
'{$_SESSION['redenBezoek']}')";

mysql_query($insert_query) or die(mysql_error());


you cannot have a field name with space so change naam Relatie to naam_Relatie that might can help you

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜