开发者

PHP and SQLite, INSERT INTO with SELECT doesn't work

I am planning to create my website; but to do this, I need to write a CMS... I've already done most of the work, but now I am getting trouble executing this code. It doesn't return any error, but it simply..doesn't do what it should do. I have three tables in my database:

users(
id_user primary key,
username unique varchar,
pwd unique varchar,
and more...
)

permissions(
id_permission INTEGER PRIMARY KEY,
permission-name varchar,
and more...
)

permissions_users ( id_permission, id_user they are foreign keys that references the same fields of the two previous tables )

I want that this snippet will check if a checkbox with the same name of the field "permission-name" is checked; if it does, the script should insert into the 3rd table the id_user and id_permission retrieved from the tables permissions and users. But 开发者_C百科it doesn't append, even if some checkboxes are checked!

Ah, I am using php 5.3.6, PDO and SQLite 3.7.4. The php code is below...

<?php

$res_perm = $db->query(
"SELECT permission-name FROM permissions"
);
while($result_perm=$res_perm->fetch()) {
if(isset($_POST[$result_perm["permission-name"]])) $db->exec(
"INSERT INTO permissions_users SELECT permissions.id_permission, users.id_user FROM permissions, users WHERE permissions.permission-name = '".$result_perm["permission-name"]."' OR users.nickname = '$ob_nickname'"
) OR die(print_r($db->errorInfo()));
}

?>


I haven't worked too much with SQLLite, but I believe the problem is with permission-name field (there is a dash(minus) sign in it, and I'm pretty sure you have to escape the it (in mysql I'd use backticks)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜