我在下面收到一条错误消息。我删除了表单以直接将值添加到 MySQL 中,但没有成功。我还将日期更改为 varchar 并多次计算所有参数。在类里面,我成功获取数据。这是一段代码。
问题出在哪里?提前致谢。
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Posts::AddPost(), 1 passed in C:....\OOP\posts.php on line 47 and exactly 10 expected in C:....\OOP\functions_oop.php:61 Stack trace: #0 C:....\OOP\posts.php(47): Posts->AddPost('1, 2 3, 4, 5, 6...') #1 {main} thrown in C:....\OOP\functions_oop.php on line 61
functions.php
public 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]);
post.php
$posts = new Posts();
$posts->AddPost("1, 2 3, 4, 5, 6, 7, 8, 9, 10");
最佳答案
应该是
$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
关于php - 未捕获的 ArgumentCountError:函数 Posts::AddPost() 的参数太少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59905967/