Change User

05/23/2012 13:25 warzie005#1
Hey there,

I have a question about PHP but it also fits in here because of the Conquer Database.

I wanna change some stuff through PHP. Only wanna look the Username up so I can change the rest. Don't wanna change the Username.

Code for the page:
PHP Code:
<?php include("include/header.php"); ?>

<div id="abouttitleblank"></div>
<div id="abouttext">

<div align="center" style="height:600px;">

<?php
if(isset($_SESSION['User_Name'])) {
if(isset(
$_SESSION['User_Pass'])) {
}
?>

<form action="?op=ChangeUser" method="post">
  <div align="center">User Changer<br />
    <br />
  </div>
  <table width="306" border="0" align="center">
  <tr>
    <td width="130" class="liteoption">Username: </td>
    <td width="166"><input name="newCP" type="text" class="liteoption" id="newCP" size="15" maxlength="13" /></td>
  </tr>
  <tr>
    <td width="130" class="liteoption">CPs: </td>
    <td width="166"><input name="CP" type="text" class="liteoption" id="CP" size="15" maxlength="13" /></td>
  </tr>
  <tr>
    <td width="130" class="liteoption">Silver: </td>
    <td width="166"><input name="Money" type="text" class="liteoption" id="Money" size="15" maxlength="13" /></td>
  </tr>
  <tr>
    <td width="130" class="liteoption">Vip: </td>
    <td width="166"><input name="Vip" type="text" class="liteoption" id="Vip" size="15" maxlength="13" /></td>
  </tr>
  <tr>
    <td width="130" class="liteoption">Reborn: </td>
    <td width="166"><input name="Reborn" type="text" class="liteoption" id="Reborn" size="15" maxlength="13" /></td>
  </tr>
  <tr>
    <td width="130" class="liteoption">Level: </td>
    <td width="166"><input name="Level" type="text" class="liteoption" id="Level" size="15" maxlength="13" /></td>
  </tr>
</table>
<p align="center">
            <input type="submit" class="liteoption" name="submit" value="Change it" />
</p></form>
</p>
<br />
<?php
if(isset($_POST['submit'])) {

$mdfive $_POST['Username']; //Change User
$mdfive $_POST['CP'];
$mdfive $_POST['Money'];
$mdfive $_POST['Vip'];
$mdfive $_POST['Reborn'];
$mdfive $_POST['Level'];


$results mysql_query("UPDATE `characters` GET Username = '".$mdfive."'");
$results mysql_query("UPDATE `characters` SET CP = '".$mdfive."'");
$results mysql_query("UPDATE `characters` SET Money = '".$mdfive."'");
$results mysql_query("UPDATE `characters` SET Vip = '".$mdfive."'");
$results mysql_query("UPDATE `characters` SET Reborn = '".$mdfive."'");
$results mysql_query("UPDATE `characters` SET Level = '".$mdfive."'");
if(!
$results) {
echo(
'Result: Password could not be changed.');
} else {
echo(
'Result: Passwords changed successfully!');
}
}
?>
<br />
<a href="user_controlpanel.php">Back To User CMD</a>
<?php ?>

</div>
</div>
<div id="newscontent"></div>

<?php include("include/footer.php"); ?>
Only wanna look the Username up so I can change the rest.
05/23/2012 16:15 turk55#2
here is the sql query: UPDATE cps From characters WHERE username='usernamehere' Set cps += 100
05/23/2012 21:45 Zeroxelli#3
Quote:
Originally Posted by turk55 View Post
here is the sql query: UPDATE cps From characters WHERE username='usernamehere' Set cps += 100
Is that even correct MySQL syntax..?
Code:
UPDATE `characters` SET `cps` = `cps` + 100 WHERE `username` = 'MyUserName'
Edit: Also, that script is complete shit. You're not even cleaning the content of the user input before passing it to MySQL. That's an SQL injection waiting to happen. ALL user input should AT LEAST be run through mysql_real_escape_string before even THINKING of passing it to the database...

Anyway, elaborate more on what you're trying to do, and I may help you.
05/23/2012 23:11 turk55#4
Quote:
Originally Posted by Zeroxelli View Post
Is that even correct MySQL syntax..?
Code:
UPDATE `characters` SET `cps` = `cps` + 100 WHERE `username` = 'MyUserName'
Edit: Also, that script is complete shit. You're not even cleaning the content of the user input before passing it to MySQL. That's an SQL injection waiting to happen. ALL user input should AT LEAST be run through mysql_real_escape_string before even THINKING of passing it to the database...

Anyway, elaborate more on what you're trying to do, and I may help you.
Ughh still had the select query in my head, was close tho.
05/23/2012 23:13 Zeroxelli#5
Quote:
Originally Posted by turk55 View Post
Ughh still had the select query in my head, was close tho.
Sadly, I don't think MySQL supports the '+=' operator anyway. So you basically have to do FieldName = FieldName + Value
05/24/2012 11:00 I don't have a username#6
His code will not work anyways. He's missing a bracket.
05/24/2012 11:14 warzie005#7
Quote:
Originally Posted by I don't have a username View Post
His code will not work anyways. He's missing a bracket.
The rest is working though.

Quote:
Originally Posted by Zeroxelli View Post
Is that even correct MySQL syntax..?
Code:
UPDATE `characters` SET `cps` = `cps` + 100 WHERE `username` = 'MyUserName'
Edit: Also, that script is complete shit. You're not even cleaning the content of the user input before passing it to MySQL. That's an SQL injection waiting to happen. ALL user input should AT LEAST be run through mysql_real_escape_string before even THINKING of passing it to the database...

Anyway, elaborate more on what you're trying to do, and I may help you.
I do not wanna give 100 but my own value. Just like the same of changing the password.

But thanks for helping me guys and girls.
05/24/2012 11:28 I don't have a username#8
Also you can sqlinject your code.
05/24/2012 18:15 Zeroxelli#9
Quote:
Originally Posted by warzie005 View Post
The rest is working though.



I do not wanna give 100 but my own value. Just like the same of changing the password.

But thanks for helping me guys and girls.
Then just change the 100 with your own value lol

Quote:
Originally Posted by I don't have a username View Post
Also you can sqlinject your code.
I said that man, he no learny learny.
05/25/2012 01:43 warzie005#10
Quote:
Originally Posted by Zeroxelli View Post
Then just change the 100 with your own value lol



I said that man, he no learny learny.
I know I can just sqlinject it. But I also wanna do that through the website. I don't wanna add the same every time. Just my OWN value that changes every time.
05/25/2012 01:54 Zeroxelli#11
Quote:
Originally Posted by warzie005 View Post
I know I can just sqlinject it. But I also wanna do that through the website. I don't wanna add the same every time. Just my OWN value that changes every time.
PHP Code:
<?php

// FreeCPs.php

if (isset($_POST['cps']) && isset($_POST['charname']) && !empty($_POST['charname']))
{
    
$cps intval($_POST['cps']);
    
$charname mysql_escape_string($_POST['charname']);
    if (
$cps && $cps 999999 && strlen($charname) >= && strlen($charname) <= 16)
    {
        
$db mysql_connect('localhost''MyDatabaseUsername''MyDatabasePassword');
        
mysql_select_db('myConquerDatabase'$db);
        
mysql_query("UPDATE `characters` SET `cps` = '{$cps}' WHERE `name` = '{$charname}' LIMIT 1"$db);
        
mysql_close($db);
    }
}

?>

<form action="./FreeCPs.php" method="post">
    <b>Char name:</b> <input name="charname" type="text" /><br />
    <b>CPs:</b> <input name="cps" type="text" /><br />
    <input type="submit" value="Gimme my CPs!" />
</form>
Have fun.
05/26/2012 01:23 turk55#12
Quote:
Originally Posted by Zeroxelli View Post
[php].
Ty for making me look up the empty function :P didn't know that yet
05/26/2012 04:07 Zeroxelli#13
Quote:
Originally Posted by turk55 View Post
Ty for making me look up the empty function :P didn't know that yet
Oh, no problem. Haha.
05/27/2012 03:31 BioHazarxPaul#14
I am a bit surprised I never had issues with mysql inject on the hellmouth website..
05/27/2012 05:47 Zeroxelli#15
Quote:
Originally Posted by BioHazarxPaul View Post
I am a bit surprised I never had issues with mysql inject on the hellmouth website..
Most people don't think to check for these exploits, and that's how most websites get taken down; either shitty scripting/security or mysql injection.