0

I have a chrome extension that only runs on Facebook and I am trying to send data that the extension gathers to a MySQL database that I have on my GoDaddy website server. I keep getting the error message "Failed to load resource: the server responded with a status of 500 (Internal Server Error)". I wasn't sure what the issue is since I'm just getting into web development. Here is my code for the content script on my chrome extension:

var dummyUrl = new URL ("http://www.bbc.com/news/world-us-canada-41081629");
  console.log("dummyUrl: " + dummyUrl);
  //Create XMLHttpRequest Object
  var xhttp = new XMLHttpRequest();
  //Send request
  xhttp.open("POST", "https://pocketchange.social/data.php", true);
  xhttp.send(dummyUrl);

And here is my PHP file on my webserver that is running a query to send the data to my database:

<?php 
$mysqli = new mysqli("localhost", "Jarid", "Database", "myURL");

//Check connection
if(mysqli === false) {
    die("ERROR: Could not connect" . $mysqli->connect_error;
}

//Print host information
echo "Connection successful. Host info: " . $mysqli->host_info;

//Escape user inputs
$url = $mysqli->real_escape_string($_REQUEST['url']);
$description = $mysqli->real_escape_string($_REQUEST['description']);
$keywords = $mysqli->real_escape_string($_REQUEST['keywords']);
$content = $mysqli->real_escape_string($_REQUEST['content']);
$language = $mysqli->real_escape_string($_REQUEST['language']);

//Execute query
$query = "INSERT INTO url_data (url, description, keywords, content, language) VALUES ('$url', '$description', '$keywords', '$content', '$language')";

//Checking to see if values were inserted properly
if($mysqli->query($query) === true) {
    echo "Data successfully inserted.";
}
else {
    echo "ERROR could not execute query" . $mysqli->error;
} 

$mysqli->close();
?>

Is my issue mainly that I'm trying to send data to a completely different server? I'm not super clear on how all of these pieces communicate with each other (ie how does the chrome extension know how to connect to the GoDaddy server, and how exactly is the php file sending data to the database, etc.) Thanks in advance.

Vanilla
  • 51
  • 1
  • 3
  • 9

1 Answers1

0

Regarding the "500 (Internal Server Error)", this highlighted SO post could give you some idea.

The 500 code would normally indicate an error on the server, not anything with your code. Some thoughts

  • Talk to the server developer for more info. You can't get more info directly.
  • Verify your arguments into the call (values). Look for anything you might think could cause a problem for the server process. The process should not die and should return you a better code, but bugs happen there also.
  • Could be intermittent, like if the server database goes down. May be worth trying at another time

You can check the post for some possible answer as well.

Hope this helps.

MαπμQμαπkγVπ.0
  • 5,887
  • 1
  • 27
  • 65