我只是想插入一个名为“艺术家”的数据库,其中包含一些不需要填写的信息。它从HTML表单中获取信息。我之前在网站上使用过这种方法,它仍在使用,字段bio,some-facebook,some-instagram,some-youtube在数据库中设置为NULL。
当我回显$sql
时,这是回声的sql字符串:
INSERT INTO artists
(name, img, bio, some-facebook, some-instagram, some-youtube)
VALUES
('Loui & Lexus','../media/coverimg/defaultcoverimg.jpg','NULL','NULL','www.instagram.com/louilexus/','NULL');`
这是我在浏览器中遇到的错误:
Fatal error: Uncaught mysqli_sql_exception: 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 '-facebook, some-instagram, some-youtube) VALUES ('Loui & Lexus','../media/coveri' at line 1 in F:\wamp64\www\hvakommerv2\include\new_artist.inc.php:88 Stack trace: #0 F:\wamp64\www\hvakommerv2\include\new_artist.inc.php(88): mysqli_query(Object(mysqli), 'INSERT INTO art...') #1 {main} thrown in F:\wamp64\www\hvakommerv2\include\new_artist.inc.php on line 88`
以下是该区域代码的片段
if ($artistLen <= 60) {
$fileDestination = "../media/coverimg/defaultcoverimg.jpg";
$sql = "INSERT INTO artists (name,img,bio,some-facebook,some-instagram,some-youtube) VALUES ('$artist','$fileDestination','$bio','$facebook','$instagram','$youtube');";
echo $sql;
mysqli_query($conn, $sql);
这是数据库的屏幕截图 https://puu.sh/yRQZO/efe7716d8c.png
答案 0 :(得分:2)
MySQL将连字符视为运算符,您应该使用下划线(some_facebook等)更改表字段名称,或者在每个字段名称上使用反引号:
...,`some-facebook`,`some-instagram`,..