• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

I need a script (php+sql)

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Reaction score
72
Location
Poland
I search for a stand alone script that will give me the ability to check a characters details form a database.

I need just like a easy example no layout needed.

1. Index page you write a players name -> the content will load or switch in a other page ( ?editcharacter=name)
2. There will be displayed like nick,lvl all form database


Regards. I really need it :))
 
index.html:
Code:
<html>
<body>
<form action="char.php" method="get">
<b>Character name:</b><input type="text" name="editcharacter" />
<input type="submit" />
</body>
</html>

char.php:
<?php
if(!isset($_GET['editcharacter']) header('Location: index.html');
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
$mysqli->query("SELECT * FROM players WHERE name = '".addslashes($_GET['editcharacter']."' LIMIT 1");
/*display here*/
 
index.html:
Code:
<html>
<body>
<script type="text/javascript"><!--
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', 'UA-7934637-1'],
['_trackPageview']
);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
//-->
</script>

<form action="char.php" method="get">
<b>Character name:</b><input type="text" name="editcharacter" />
<input type="submit" />
</body>
</html>

char.php:

Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\aapal\char.php on line 2
 
Change if(!isset($_GET['editcharacter']) header('Location: index.html'); to if(!isset($_GET['editcharacter'])) header('Location: index.html');
 
Thanks Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\aapal\char.php on line 4

whole line 4 is a bit messy ;S
 
Change
PHP:
$mysqli->query("SELECT * FROM players WHERE name = '".addslashes($_GET['editcharacter']."' LIMIT 1");
to
PHP:
$mysqli->query("SELECT * FROM players WHERE name = '".addslashes($_GET['editcharacter'])."' LIMIT 1");
 
PHP:
<?PHP

    if ( !isset( $_GET['editcharacter'] ) header( 'Location: index.html' );
    
    $mysqli = new mysqli( 'localhost', 'my_user', 'my_password', 'my_db' );
    $result = $mysqli->query( 'SELECT * FROM `players` WHERE `name` = \''.$mysqli->real_escape_string( $_GET['editcharacter'] ).'\' LIMIT 1;' )->fetch_assoc( );
    
    
    // Display all columns
    echo '<pre>';
    print_r( $result );
    echo '</pre>';
    
    // Display a single column
    echo $result['name'];
 
Really helpful <rep>. Tell me what about a possibility to edit such columns ( values ) and save them into the database :)?
 
PHP:
if ( isset( $_POST['input'] ) ) {
     $mysqli->query( 'UPDATE `players` SET `field` = \''.$mysqli->real_escape_string( $_POST['input'] ).'\';' );
}
 
Something like this should do I suppose. Remember, this is just a quick example. A lot of adjustments could be done.
PHP:
<?PHP

    if ( !isset( $_GET['editcharacter'] ) header( 'Location: index.html' );
    
    $mysqli = new mysqli( 'localhost', 'my_user', 'my_password', 'my_db' );
    $result = $mysqli->query( 'SELECT * FROM `players` WHERE `name` = \''.$mysqli->real_escape_string( $_GET['character'] ).'\' LIMIT 1;' )->fetch_assoc( );


    if ( !isset( $_POST['submit'] ) )
    {
        ?>
        <form method="post" action="">
            <strong>Edit Field:</strong><br />
            <select name="field">
                <?PHP
                    foreach( $result as $key => $value )
                    {
                        echo '<option value="'.$key.'">'.$key.'</option>';
                    }
                ?>
            </select><br />
            <input type="text" name="new" />
            <input type="submit" name="submit" value="Edit!" />
        </form>
        <br />
        <?PHP
            echo '<pre>';
            print_r( $result );
            echo '</pre>';
    }
    else
    {
        $mysqli->query( 'UPDATE `players` SET `'.$mysqli->real_escape_string( $_POST['field'] ).'` = \''.$mysqli->real_escape_string( $_POST['new'] ).'\';' );    
    }
    
?>
 
Something like this should do I suppose. Remember, this is just a quick example. A lot of adjustments could be done.
Code:
<?PHP

    if ( !isset( $_GET['editcharacter'] ) header( 'Location: index.html' );
    
    $mysqli = new mysqli( 'localhost', 'my_user', 'my_password', 'my_db' );
    $result = $mysqli->query( 'SELECT * FROM `players` WHERE `name` = \''.$mysqli->real_escape_string( $_GET['character'] ).'\' LIMIT 1;' )->fetch_assoc( );


    if ( !isset( $_POST['submit'] ) )
    {
        ?>
        <form method="post" action="">
            <strong>Edit Field:</strong><br />
            <select name="field">
                <?PHP
                    foreach( $result as $key => $value )
                    {
                        echo '<option value="'.$key.'">'.$key.'</option>';
                    }
                ?>
            </select><br />
            <input type="text" name="new" />
            <input type="submit" name="submit" value="Edit!" />
        </form>
        <br />
        <?PHP
            echo '<pre>';
            print_r( $result );
            echo '</pre>';
    }
    else
    {
        $mysqli->query( 'UPDATE `players` SET `'.$mysqli->real_escape_string( $_POST['field'] ).'` = [b]\''.$mysqli->real_escape_string( $_POST['new'] ).'\'[/b];' );    
    }
    
?>
why do u escape 2 times??
 
PineIT or someone i tried to create a query i hope you understand it..

$accountresult = $mysqli->query( 'SELECT * FROM `players` WHERE `name` = \''.$mysqli->real_escape_string( $_GET['editcharacter'] ).'\' AND SELECT * FROM accounts WHERE id='.$result['id'].' LIMIT 1;' );

It should also select * all from accounts while the player is loaded. To get f.e a account number/email etc.

Something like this should do I suppose. Remember, this is just a quick example. A lot of adjustments could be done.
PHP:
<?PHP

    if ( !isset( $_GET['editcharacter'] ) header( 'Location: index.html' );
    
    $mysqli = new mysqli( 'localhost', 'my_user', 'my_password', 'my_db' );
    $result = $mysqli->query( 'SELECT * FROM `players` WHERE `name` = \''.$mysqli->real_escape_string( $_GET['character'] ).'\' LIMIT 1;' )->fetch_assoc( );


    if ( !isset( $_POST['submit'] ) )
    {
        ?>
        <form method="post" action="">
            <strong>Edit Field:</strong><br />
            <select name="field">
                <?PHP
                    foreach( $result as $key => $value )
                    {
                        echo '<option value="'.$key.'">'.$key.'</option>';
                    }
                ?>
            </select><br />
            <input type="text" name="new" />
            <input type="submit" name="submit" value="Edit!" />
        </form>
        <br />
        <?PHP
            echo '<pre>';
            print_r( $result );
            echo '</pre>';
    }
    else
    {
        $mysqli->query( 'UPDATE `players` SET `'.$mysqli->real_escape_string( $_POST['field'] ).'` = \''.$mysqli->real_escape_string( $_POST['new'] ).'\';' );    
    }
    
?>

Seems that it dont display any value in the field list possible?
 
Last edited by a moderator:
why do u escape 2 times??
I am only escaping it once. Those are two different values.

PineIT or someone i tried to create a query i hope you understand it..
It should also select * all from accounts while the player is loaded. To get f.e a account number/email etc.
PHP:
$mysqli->query( 'SELECT * FROM `players` LEFT JOIN `accounts` ON `accounts`.`id` = `players`.`account_id` WHERE `players`.`name` = \''.$mysqli->real_escape_string( $_GET['editcharacter'] ).'\';' )->fetch_assoc( );
Seems that it dont display any value in the field list possible?
It does for me. You have to add ?editcharacter=NAME at the end of your URL bar.
 
I am only escaping it once. Those are two different values.

PHP:
$mysqli->query( 'SELECT * FROM `players` LEFT JOIN `accounts` ON `accounts`.`id` = `players`.`account_id` WHERE `players`.`name` = \''.$mysqli->real_escape_string( $_GET['editcharacter'] ).'\';' )->fetch_assoc( );
It does for me. You have to add ?editcharacter=NAME at the end of your URL bar.

W0w really i appreciate you work. I hope you might help me in the coming time. I will post here my requests :) Nice to see a person that can help.
 
Btw. Your field editor work properly but as you see i wanted a bit other result. I wanted to have a ability to change

HTML:
 Name :
   <?PHP echo $result['name']; ?>

simple fields or just displayed like this. Like if you have for example the Players name field 'name' i want have :|:

PHP:
 Player name :  <?PHP echo $result['name']; ?> <input type="field" value="<?PHP ?GET_field value from the database(this one)?; ?> 
Player level:  <?PHP echo $result['level']; ?> <input type="field" value="<?PHP ?GET_field value from the database(this one)?; ?> 
Player mlvl:  <?PHP echo $result['mlvl']; ?> <input type="field" value="<?PHP ?GET_field value from the database(this one)?; ?> 

  <input type="submit" name="submit" value="Apply Changes" />
 
PHP:
echo '<strong>Name:</strong> <input type="text" name="name" value="'.$result['name'].'" /><br />';
echo '<strong>Whatever:</strong> <input type="text" name="whatever" value="'.$result['whatever'].'" /><br />';
 
And what about saving all the fields? Look here

f27iaw.jpg
 
Back
Top