为什么我的 POST 请求在 MIT App Inventor 中不起作用?

问题描述 投票:0回答:0

我正在 MIT App Inventor 上创建我的第一个应用程序,我正在尝试向我的 mySQL 数据库发送 POST 请求,但它不起作用。我的 GetRequest 正在工作,所以我知道我与数据库有连接,但我不断从我的 POST 请求中收到代码 500,表明数据库不理解该请求。我粘贴了下面的代码(第二张图片只是其余的键)。

这里是 PHP 代码:


// set up the response array
$response = array();

// check if the request method is POST
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
 // get the userid from the POST request
 $userid = $_POST['userid'];
$imagekey = $_POST['imagekey'];
$glad = $_POST['glad'];
$delighted = $_POST['delighted'];
$overjoyed = $_POST['overjoyed'];
$competent = $_POST['competent'];
$proud = $_POST['proud'];
$daring = $_POST['daring'];
$accepted = $_POST['accepted'];
$valued = $_POST['valued'];
$admired = $_POST['admired'];
$liked = $_POST['liked'];
$loved = $_POST['loved'];
$adored = $_POST['adored'];
$alone = $_POST['alone'];
$lonely = $_POST['lonely'];
$isolated = $_POST['isolated'];
$slighted = $_POST['slighted'];
$disrespected = $_POST['disrespected'];
$humiliated = $_POST['humiliated'];
$letdown = $_POST['letdown'];
$disappointed = $_POST['disappointed'];
$crushed = $_POST['crushed'];
$uncertain = $_POST['uncertain'];
$weak = $_POST['weak'];
$helpless = $_POST['helpless'];
$lost = $_POST['lost'];
$hopeless = $_POST['hopeless'];
$suicidal = $_POST['suicidal'];
$unhappy = $_POST['unhappy'];
$sad = $_POST['sad'];
$miserable = $_POST['miserable'];
$annoyed = $_POST['annoyed'];
$frustrated = $_POST['frustrated'];
$furious = $_POST['furious'];
$upset = $_POST['upset'];
$bitter = $_POST['bitter'];
$indignant = $_POST['indignant'];
$worried = $_POST['worried'];
$threatened = $_POST['threatened'];
$terrified = $_POST['terrified'];



 echo $userid;

 // connect to the database
 require_once "config.php";

 // insert the record into the database
 $sql = "INSERT INTO data (userid, imagekey, glad, delighted, overjoyed, competent, proud, daring, accepted, valued, admired, liked, loved, adored, alone, lonely, isolated, slighted, disrespected, humiliated, letdown, disappointed, crushed, uncertain, weak, helpless, lost, hopeless, suicidal, unhappy, sad, miserable, annoyed, frustrated, furious, upset, bitter, indignant, worried, threatened, terrified) VALUES (:userid, :imagekey, :glad, :delighted, :overjoyed, :competent, :proud, :daring, :accepted, :valued, :admired, :liked, :loved, :adored, :alone, :lonely, :isolated, :slighted, :disrespected, :humiliated, :letdown, :disappointed, :crushed, :uncertain, :weak, :helpless, :lost, :hopeless, :suicidal, :unhappy, :sad, :miserable, :annoyed, :frustrated, :furious, :upset, :bitter, :indignant, :worried, :threatened, :terrified)";
 $stmt = $pdo->prepare($sql);
 $stmt->bindParam(':userid', $userid);
$stmt->bindParam(':imagekey', $imagekey);
$stmt->bindParam(':glad', $glad);
$stmt->bindParam(':delighted', $delighted);
$stmt->bindParam(':overjoyed', $overjoyed);
$stmt->bindParam(':competent', $competent);
$stmt->bindParam(':proud', $proud);
$stmt->bindParam(':daring', $daring);
$stmt->bindParam(':accepted', $accepted);
$stmt->bindParam(':valued', $valued);
$stmt->bindParam(':admired', $admired);
$stmt->bindParam(':liked', $liked);
$stmt->bindParam(':loved', $loved);
$stmt->bindParam(':adored', $adored);
$stmt->bindParam(':alone', $alone);
$stmt->bindParam(':lonely', $lonely);
$stmt->bindParam(':isolated', $isolated);
$stmt->bindParam(':slighted', $slighted);
$stmt->bindParam(':disrespected', $disrespected);
$stmt->bindParam(':humiliated', $humiliated);
$stmt->bindParam(':letdown', $letdown);
$stmt->bindParam(':disappointed', $disappointed);
$stmt->bindParam(':crushed', $crushed);
$stmt->bindParam(':uncertain', $uncertain);
$stmt->bindParam(':weak', $weak);
$stmt->bindParam(':helpless', $helpless);
$stmt->bindParam(':lost', $lost);
$stmt->bindParam(':hopeless', $hopeless);
$stmt->bindParam(':suicidal', $suicidal);
$stmt->bindParam(':unhappy', $unhappy);
$stmt->bindParam(':sad', $sad);
$stmt->bindParam(':miserable', $miserable);
$stmt->bindParam(':annoyed', $annoyed);
$stmt->bindParam(':frustrated', $frustrated);
$stmt->bindParam(':furious', $furious);
$stmt->bindParam(':upset', $upset);
$stmt->bindParam(':bitter', $bitter);
$stmt->bindParam(':indignant', $indignant);
$stmt->bindParam(':worried', $worried);
$stmt->bindParam(':threatened', $threatened);
$stmt->bindParam(':terrified', $terrified);

 $stmt->execute();

 // set the success message in the response array
 $response['error'] = false;
 $response['message'] = 'Record inserted successfully';
} else {
 // set the error message in the response array
 $response['error'] = true;
 $response['message'] = 'You are not authorized';

}

// return the response as JSON
echo json_encode($response);


// close the database connection
unset($pdo);```
php mysql pdo app-inventor
© www.soinside.com 2019 - 2024. All rights reserved.