You are viewing our Forum Archives. To view or take place in current topics click here.
Runescape API help ARRAY
Posted:
Runescape API help ARRAYPosted:
Status: Offline
Joined: Jan 24, 201311Year Member
Posts: 71
Reputation Power: 2
Status: Offline
Joined: Jan 24, 201311Year Member
Posts: 71
Reputation Power: 2
Hello, I am trying to create a hiscores website although i am not quite good with arrays, but this is what i am trying to do once the user enters there username using the $_GET['player'] then it will pull the information from Runescapes API from which i want it to store in my database using PDO.
I just need help with the parsing the arrays and inserting them into my database with some basic validation.
if anymore information is required i can provide
Thanks.
I just need help with the parsing the arrays and inserting them into my database with some basic validation.
if anymore information is required i can provide
Thanks.
#2. Posted:
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Post an example of the data you're getting back from the API.
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Jan 24, 201311Year Member
Posts: 71
Reputation Power: 2
Status: Offline
Joined: Jan 24, 201311Year Member
Posts: 71
Reputation Power: 2
#4. Posted:
Status: Offline
Joined: Mar 21, 201014Year Member
Posts: 4,083
Reputation Power: 781
Status: Offline
Joined: Mar 21, 201014Year Member
Posts: 4,083
Reputation Power: 781
#5. Posted:
Status: Offline
Joined: Jan 24, 201311Year Member
Posts: 71
Reputation Power: 2
Status: Offline
Joined: Jan 24, 201311Year Member
Posts: 71
Reputation Power: 2
Emmy wroteKLArcher wrotespeed wrote Post an example of the data you're getting back from the API.
[ Register or Signin to view external links. ]
Broken link
The link works fine, the account that was on there which was 11 Smith 2hp got suspended just remove the 11 Smith 2hp from the end of URL and just put Vault.
- 0useful
- 0not useful
#6. Posted:
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Well the data is sent back in CSV format.
You can use String.split(",") to get back each value in a seperate position in an array.
I would advise putting all the values into a String array first considering some of them have spaces in the response.
Javascript
PHP
If you are doing all this work locally, you should be fine to not have to handle XSS and SQL injection.
If you are hosting the server online, look up [ Register or Signin to view external links. ] .
You can use String.split(",") to get back each value in a seperate position in an array.
I would advise putting all the values into a String array first considering some of them have spaces in the response.
Javascript
// Connect to the API
// Retrieve the results from API script.
var results = // API response
/*
Depending on which values you need to use, get them
from the array and use them.
*/
XMLHttpRequest xhr = new XMLHttpRequest(); // Create a new ajax request
var url = "savetodatabase.php"; // Set the php script to send the data to
var query = "username=" + results[0] + "&score=" + results[1]; // Set the query parameters
xhr.open("POST", url, true); // Open the request to the server, provide the php script and set the operation to asynchronous
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // Set the header information
xhr.onreadystatechange = function() { // Do this function when the state changes
if(xhr.readyState == 4 && xhr.status == 200) {
alert(xhr.responseText); // Show an alert with the response from the server
}
}
xhr.send(query); // Send the request
PHP
<?php
// Get the values sent in
$username = $_POST["username"];
$score = $_POST["score"];
// Create a new instance of PDO
$conn = new PDO("mysql:host=localhost;dbname=database_name;", "username", "password");
// Insert the values into the table.
$result = $conn->query("INSERT INTO tablename(column1, column2) VALUES ($username, $score");
// If the result was successful, $result will hold the number of affected rows hence
// if it is greater than 0, it was successful
if ($result->rowCount() > 0) {
echo "Database updated successfully."; // Return success message to browser
} else {
echo "Operation failed."; // Return failure message to browser
}
?>
If you are doing all this work locally, you should be fine to not have to handle XSS and SQL injection.
If you are hosting the server online, look up [ Register or Signin to view external links. ] .
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.