我有tag1,tag2,tag3
形式的标签,我想输入一个表格,即
tag_id tag_name topic_id
1 php 1
2 ajax 2
3 mysql 3
4 html 4
以下脚本不会这样做。我在屏幕上没有任何错误
$topic_tag = explode("," , $topic_tags) ;
foreach($topic_tag as $topic_tags) {
$query = "INSERT INTO `forum_tags` (`tag_id`, `tag_name`)
VALUES ( NULL, '" .mysql_real_escape_string(trim($topic_tags))."')";
}
答案 0 :(得分:2)
考虑将PDO用于SQL请求: http://php.net/manual/en/book.pdo.php
例如:
$statement = $pdo_object->prepare('INSERT INTO `forum_tags` (`tag_id`, `tag_name`, `topic_id` ) VALUES ( ?, ?, ?) ');
$statement->execute( $topic_tags );