Created
April 22, 2012 12:40
-
-
Save Morse-Code/2463973 to your computer and use it in GitHub Desktop.
MySQL Writer-Simple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$arr = array(); | |
$arr[0] = $_POST["PID"]; | |
$arr[1] = $_POST["VER"]; | |
// Connect database. | |
$host="localhost"; | |
$db_user="USER_OF_DATABASE_VARIABLE"; //Whatever your user name is | |
$db_password="USER_OF_DATABASE_VARIABLE_PASSWORD"; | |
$database="NAME_OF_DATABASE"; | |
$db = mysql_connect($host,$db_user,$db_password); | |
if (!($db)){ | |
echo "SQL ERROR: Connection failed: "; //I echo this so it responds to Java applet | |
die('SQL ERROR: Connection failed: ' . mysql_error($db)); | |
} | |
$dbSelected = mysql_select_db($database,$db); | |
if(!$dbSelected){ | |
echo "SQL ERROR: Selection Failed "; | |
die("Can\'t use ".$database." ".mysql_error()); | |
} | |
$sql = "insert into Game1 values (".$arr[0].",".$arr[1].")"; | |
if (!($db2 = mysql_query($sql, $db))){ | |
echo "SQL INSERT "; | |
die('SQL INSERT ERROR: '.mysql_error(). " - Query was: {$sql}"); | |
} | |
echo "success"; //RESPOND TO APPLET | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean postResults(int pid, int ver) throws MalformedURLException, IOException { | |
boolean success = false; | |
String parametersAsString = "PID=" + pid + "&VER=" + ver; | |
byte[] parameterAsBytes = parametersAsString.getBytes(); | |
URL url = this.getCodeBase(); | |
url = new URL(url + "updateDD.php"); | |
URLConnection con = url.openConnection(); | |
((HttpURLConnection) con).setRequestMethod("POST"); | |
con.setDoOutput(true); | |
con.setDoInput(true); | |
con.setUseCaches(false); | |
OutputStream oStream = con.getOutputStream(); | |
oStream.write(parameterAsBytes); | |
oStream.flush(); | |
BufferedReader iStream = new BufferedReader(new InputStreamReader(con.getInputStream())); | |
String aLine = iStream.readLine(); | |
while(aLine != null){ | |
if(aLine.contains("success")) | |
success = true; | |
if(aLine.equals("")) break; | |
aLine = iStream.readLine(); | |
} | |
iStream.close(); | |
oStream.close(); | |
return success; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment