May not work, I wrote it here and has not been tested but I do not see a reason why it should not
. SQL injection is not possible since we compare the given string with an array and do not execute query directly so no additional filters are necessary. Probably not the best solution but good for MuOnline.
HTML:
<form method="post">
<input type= " text" name="character">
<input type= " number" name="credits">
<input type= " submit" value="send">
</form>
PHP:
<?php
function check_char($char){
$all_chars = mssql_query("Select * from Character");
while($result = mssql_fetch_array($all_chars)){
$array = array()
$array[] = $result['Name'];
}
if(in_array($char, $array)){
return($result['AccountID']);
}
else{
return false;
}
}
if (isset($_POST['credits']) && isset($_POST['character']) ){
$credits = int($_POST['credits']);
$my_credits = mssql_fetch_array(mssql_query("Select * from memb_credits where memb___id = '".$_SESSION['mysession']."'"));
if($my_credits['credits'] > 0 && $mycredits['credits'] <= $credits && $credits > 0 && check_char($_POST['character'])){
mssql_query("Update Memb_Credits set credits = credits + $credits where memb___id='".check_char($_POST['character'])."'");
echo"Well done ";
}
else{
echo "Fill the fields properly";
}
}