**enter code here**
我是第一次使用 CodeIgniter 开发人员,我正在开发一个自我诊断 Web 应用程序。在这个应用程序中,我有一个选项卡,用户可以在其中输入他们的症状,系统将根据输入生成结果。我面临的挑战是我想将系统的输出保存到 mysql 数据库表中。
为了自我诊断,我集成了一个chatgpt API。下面是为用户打印输出的代码片段
<?php
// $this->load->database();
if(isset($_POST['str'])){
$ch = curl_init();
$str=$_POST['str'];
curl_setopt($ch, CURLOPT_URL, 'https://api.openai.com/v1/completions');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$postdata=array(
"model"=> "text-davinci-003",
"prompt"=> $str,
"temperature"=> 0.7,
"max_tokens"=> 1400,
"top_p"=> 1,
"frequency_penalty"=> 0,
"presence_penalty"=> 0
);
$postdata=json_encode($postdata);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$headers = array();
$headers[] = 'Content-Type: application/json';
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$result=json_decode($result,true);
echo $result['choices'] [0] ['text'];
}
Two errors:
1.
Severity: Notice
Message: Array to string conversion
Filename: database/DB_driver.php
Here's the error number 2
Error Number: 1054
Unknown column 'Array' in 'field list'
INSERT INTO `responses` (`responses`) VALUES (Array)