I already have the framework for the connection, I think i just have an error in my MIT App Inventor Code. The empty socket was just for testing something else, i had the error even without the empty socket. Right now im testing with a public database, but when i was testing with my own local host, the connection KeepAlive fixed my issue with localhost.
Here is the insert.php (Although i'm pretty sure it's working:)
<?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'];
$otheremotion = $_POST['otheremotion'];
echo $userid;
// connect to the database
require_once "config.php";
// insert the record into the database
$sql = "INSERT INTO stardata (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, otheremotion) 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, :otheremotion)";
$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->bindParam(':otheremotion', $otheremotion);
$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);