dongni8969 2019-01-22 23:48
浏览 43

使用php的chatfuel json api post方法

I want to save user's input in my chatbot to my database. I am trying to use POST API in PHP. This is the code:

<?php
if (isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
$gender = $_POST['gender'];
$email = $_POST['email'];
$phoneCode = $_POST['phoneCode'];
$phone = $_POST['phone'];
if (!empty($username) || !empty($password) || !empty($gender) || 
 !empty($email) || !empty($phoneCode) || !empty($phone)) {
$host = "localhost";
$dbUsername = "id8525516_anas";
$dbPassword = "12345678";
$dbname = "id8525516_testdb";
//create connection
$conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
if (mysqli_connect_error()) {
 die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error());
} else {
 $SELECT = "SELECT email From testTable Where email = ? Limit 1";
 $INSERT = "INSERT Into testTable (username, password, gender, email, phoneCode, phone) values(?, ?, ?, ?, ?, ?)";
 //Prepare statement
 $stmt = $conn->prepare($SELECT);
 $stmt->bind_param("s", $email);
 $stmt->execute();
 $stmt->bind_result($email);
 $stmt->store_result();
 $rnum = $stmt->num_rows;
 if ($rnum==0) {
  $stmt->close();
  $stmt = $conn->prepare($INSERT);
  $stmt->bind_param("ssssii", $username, $password, $gender, 
$email, $phoneCode, $phone);
  $stmt->execute();
  echo "New record inserted sucessfully";
 } else {
  echo "Someone already register using this email";
 }
 $stmt->close();
 $conn->close();
}
} else {
echo "All field are required";
die();
}
}
else{
echo 'error occurred';
}
?>

the link in the json api card in chatfuel is:

https://httpsapi.000webhostapp.com/index.php?username= {{username}}&password={{password}}&gender={{gender}}&email={{email}}&phoneCode={{phoneCode}}&phone={{phone}}&submit=Submit

This gives error and the database is not updated. Please point out how can I make it work. Note: I'm very new to php code. Thanks,

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 vue3加ant-design-vue无法渲染出页面
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 路易威登官网 里边的参数逆向
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程
    • ¥20 模型在y分布之外的数据上预测能力不好如何解决
    • ¥15 processing提取音乐节奏
    • ¥15 gg加速器加速游戏时,提示不是x86架构
    • ¥15 python按要求编写程序