[REQUEST]PHP Script

05/21/2010 18:42 WarpGeorge#1
Hello. Can someone, who's having a good knowledge about PHP, make a PHP script that's resets, to a desired character, the amount of money? Like 2 boxes one for Character Name and one for Password and then a button for "Reset" that reads the character money and reset him to 0 if his money are over 999k? If I didn't explained well I'll explain my request again and if it's to hard I request to close this topic.
05/21/2010 20:12 kinshi88#2
This should be just about what you need, it's nothing great just made it real quick.
You'll have to edit it a bit to fit your database (table names etc) but should work.

Code:
<?php
	$mysql_hostname =  "localhost";
	$mysql_user = 	   "USERNAME";
	$mysql_password =  "PASSWORD";
	$mysql_database =  "DATABASE";
?>

<?php
	if (isset($_POST['uid']) && isset($_POST['gold'])) {
		$user = $_POST['uid'];
		$gold = $_POST['gold'];
		
		$mysql_con = mysql_connect($mysql_hostname, $mysql_user, $mysql_password)
		or die("Unable to connect to database.");
		mysql_select_db($mysql_database, $mysql_con) or die("Unable to select database.");
		
		$sql = "UPDATE characters SET Gold = 0 WHERE UID = '$uid'";
		
		if (!mysql_query($sql))
			die('Error: ' . mysql_error());
		echo "Updated!";
	}
	else if (isset($_POST['user']) && isset($_POST['pass'])) {
		$user = $_POST['user'];
		$pass = $_POST['pass'];
		
		$mysql_con = mysql_connect($mysql_hostname, $mysql_user, $mysql_password)
		or die("Unable to connect to database.");
		mysql_select_db($mysql_database, $mysql_con) or die("Unable to select database.");
		
		$sql = "SELECT UID FROM accounts WHERE Account = '$user' AND Password_Plain = '$pass'";
		
		$uid = mysql_result(mysql_query($sql), 0) or die("Invalid Username or password.");
		
		$sql2 = "SELECT Gold FROM characters WHERE UID = $uid";
		
		$result = mysql_query($sql2) or die("Invalid UID.");
		
		
		if ($row = mysql_fetch_array($result)) {
			$gold = $row['Gold'];
			echo "Money: $gold<br />";
			if ($gold >= 999999) {
				echo "<form method='post'>";
				echo "<input type='hidden' value=$uid name='uid' />";
				echo "<input type='hidden' value=$gold name='gold' />";
				echo "<input type='submit' value='Reset to 0' />";
				echo "</form>";
			}
		}
	}
?>

<form method="post">
<table>
	<tr>
		<td>Username:</td>
		<td><input type='text' name='user' /></td>
	</tr>
	<tr>
		<td>Password:</td>
		<td><input type='password' name='pass' /></td>
	</tr>
	<tr>
		<td></td>
		<td><input type='submit' value="Find" /></td>
	</tr>
</table>
<form>
05/21/2010 21:44 DePredaTe#3
Kinshi, you cant really make it unless you know what source.
it could be flat file.
05/21/2010 22:14 gerble93#4
Quote:
Originally Posted by DePredaTe View Post
Kinshi, you cant really make it unless you know what source.
it could be flat file.
You shouldn't criticise Kinshi..he did what the person asked for with the information he best could get.
05/21/2010 22:36 DePredaTe#5
i wasn't criticizing kinshi at all.
if i was going to criticize anyone it should be the poster. Kinshi was just trying to help.
I don't understand how people expect people to write PHP script for their server if you don't even post the information needed. He posted what he wanted, not what he needed.
05/22/2010 00:50 ImmuneOne#6
Quote:
Originally Posted by kinshi88 View Post
This should be just about what you need, it's nothing great just made it real quick.
You'll have to edit it a bit to fit your database (table names etc) but should work.
MysqlConfig.cs
Code:
<?php

$mysql_hostname =  "localhost";
$mysql_user = 	   "USERNAME";
$mysql_password =  "PASSWORD";
$mysql_database =  "DATABASE";

?>
MysqlBase.cs
Code:
<?php

public class MysqlBase
{
   var $_Connection = null;
   var $_Reader = null;
   var $_Command = null;
   var $_Query = null;
   var $_Result = null;

   public function MysqlBase()
   {
     $this->_Connection = mysql_connect($mysql_hostname, $mysql_user, $mysql_password)
		or die("Unable to connect to database.");
   }
    
   public function Select($Table, $Section, $FromSection, $FromValue)
   {
     mysql_select_db($mysql_database, $this->_Connection) or die("Unable to select database.");
     $this->_Command = "SELECT $Section FROM $TABLE WHERE $FromSection = '$FromValue'";
     $this->_Reader = mysql_result(mysql_query($this->_Command), (0) or die("Data not found.");
     $this->_Query = mysql_query($this->_Command) or die("Data not found.");
   }
   
   public function Read($Section)
   {
     var $_Value = null;

     if($this->_Result = mysql_fetch_array($this->_Query)
     {
       $_Value = $this->_Result['$Section']; 
     }
     return $_Value;
   }
}

?>
I don't see the point of recreating the connection everytime :rolleyes:
05/23/2010 01:58 WarpGeorge#7
Request was for a 5095 database (binaries). I'll try to edit where needed to get this script working. Thanks anyway kinshi even this will not work. I'm trying out now
05/23/2010 02:07 WarpGeorge#8
Neah doesn't work ! I wanted this PHP script to prevent people making money glitch ( getting over 2,5 billions gold) but I had an idea and re-scripted the Exchanger (NPC which's exchanging your CPs for gold and made a line which's it's reading the value of your character money and if you have more or equal to 999kk give you a fail msg and stop exchanging you money). I request to close this topic but don't delete it because maybe some people will need that kinshi work or Immuneone. ty and sorry for disturbing you people with that script. i`ll never ask again for something that can be done with another methods that i have knowledge about them :) sorry again