首先,我尝试用这个PHP脚本填充数据库。我收到的错误是 - “你的SQL语法有错误;请查看与你的MySQL服务器版本相对应的手册,以便在第1行的''附近使用正确的语法”我明白错误是什么我只是看不出来找到它。
<?php
include("server_connect.php");
//select the db
mysql_select_db("moviedatabase");
//populate titles
$insert = "INSERT INTO tblMovieTitle (movie_id, movie_title, movie_genre, movie_rating, movie_actor_fname, movie_actor_lname) " .
"VALUES (1, 'Inglorious Basterds', 'War', 8, 'Brad', 'Pitt'), " .
"(2, 'Zombieland', 'Comedy', 8, 'Jesse', 'Eisenberg'), " .
"(3, 'Cowboys and Aliens', 'Action', 6, 'Olivia', 'Wilde'), " .
"(4, 'Contagion', 'Drama', 7, 'Matt', 'Damon')";
$results = mysql_query($insert) or die (mysql_error());
//populate genre
$genre = "INSERT INTO tblMovieGenre (movie_genre_ID, movie_genre) " .
"VALUES (100, 'Action'), " .
"(101, 'Horror'), " .
"(102, 'Comedy'), " .
"(103, 'War'), " .
"(104, 'Drama'), " .
"(105, 'Kids'), " .
"(106, 'Sci-Fi'), " .
"(107, 'Action'), " ;
$results = mysql_query($genre) or die (mysql_error());
//populate movie rating
$rating = "INSERT INTO tblMovieRating (movie_rating_ID, movie_rating ) " .
"VALUES (1001, 1), " .
"(1002, 2), " .
"(1003, 3), " .
"(1004, 4), " .
"(1005, 5), " .
"(1006, 6), " .
"(1007, 7), " .
"(1008, 8), " .
"(1009, 9), " .
"(1010, 10)";
$results = mysql_query($rating) or die (mysql_error());
//check if database is populated
echo "Database populated";
?>
是的所以我真的无法弄清楚错误来自哪里,有人吗?先谢谢你的帮助。
答案 0 :(得分:1)
"(107, 'Action'), " ;
您不需要额外的逗号,