我在下面收到一条错误消息。我删除了表单以将值直接添加到MySQL中,但没有成功。我还将日期更改为varchar,并多次计算所有参数。在类中,我成功获取了数据。下面是一段代码。问题出在哪里?提前致谢。致命错误:未捕获的 ArgumentCountError:函数参数太少 Posts::AddPost(),在 C:....\OOP\posts.php 在第 47 行传递 10 个,在 C:...中预期为 10 个,在 C:....\OOP\functions_oop.php:61 堆栈跟踪:#0 C:....\OOP\posts.php(47): Posts->AddPost('1, 2 3, 4, 5, 6...') #1 {main} 在 C:....\OOP\functions_oop.php 行第 61 行函数.phppublic function AddPost($date, $title, $gallery, $website, $thumbnail, $categories, $tags, $model, $local, $status) { $sql = "INSERT INTO posts (post_date, post_title, post_gallery, post_website, post_thumbnail, post_categories, post_tags, post_model, post_local, post_status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $stmt = $this->connect()->prepare($sql); $stmt->execute([$date, $title, $gallery, $website, $thumbnail, $categories, $tags, $model, $local, $status]);帖子.php$posts = new Posts();$posts->AddPost("1, 2 3, 4, 5, 6, 7, 8, 9, 10");
1 回答

潇湘沐
TA贡献1816条经验 获得超6个赞
它应该是
$posts->AddPost( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // 10 arguments, 10 integers
而不是
$posts->AddPost("1, 2 3, 4, 5, 6, 7, 8, 9, 10"); // 1 argument: a string
- 1 回答
- 0 关注
- 108 浏览
添加回答
举报
0/150
提交
取消