I need a script (php+sql)

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Best answers
0
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 :))
 

stian

Banned User
Joined
Oct 29, 2009
Messages
3,755
Best answers
0
Reaction score
49
Location
Norway
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*/
 
OP
Kavvson

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Best answers
0
Reaction score
72
Location
Poland
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
 

PineIt

Web Developer
Joined
Sep 9, 2010
Messages
50
Best answers
0
Reaction score
4
Change if(!isset($_GET['editcharacter']) header('Location: index.html'); to if(!isset($_GET['editcharacter'])) header('Location: index.html');
 
OP
Kavvson

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Best answers
0
Reaction score
72
Location
Poland
Thanks Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\aapal\char.php on line 4

whole line 4 is a bit messy ;S
 

PineIt

Web Developer
Joined
Sep 9, 2010
Messages
50
Best answers
0
Reaction score
4
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");
 
OP
Kavvson

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Best answers
0
Reaction score
72
Location
Poland
Thanks tell me .. a example of display for example the "health" $mysqli['health']?
 

PineIt

Web Developer
Joined
Sep 9, 2010
Messages
50
Best answers
0
Reaction score
4
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'];
 
OP
Kavvson

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Best answers
0
Reaction score
72
Location
Poland
Really helpful <rep>. Tell me what about a possibility to edit such columns ( values ) and save them into the database :)?
 

PineIt

Web Developer
Joined
Sep 9, 2010
Messages
50
Best answers
0
Reaction score
4
PHP:
if ( isset( $_POST['input'] ) ) {
     $mysqli->query( 'UPDATE `players` SET `field` = \''.$mysqli->real_escape_string( $_POST['input'] ).'\';' );
}
 
OP
Kavvson

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Best answers
0
Reaction score
72
Location
Poland
Im kinda noobish in that part. Could you write me an example :) then it will be clear for me
 

PineIt

Web Developer
Joined
Sep 9, 2010
Messages
50
Best answers
0
Reaction score
4
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'] ).'\';' );    
    }
    
?>
 

Fallen

Freelancer
Joined
Aug 21, 2009
Messages
3,713
Best answers
0
Reaction score
246
Location
Egypt
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??
 
OP
Kavvson

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Best answers
0
Reaction score
72
Location
Poland
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:

PineIt

Web Developer
Joined
Sep 9, 2010
Messages
50
Best answers
0
Reaction score
4
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.
 
OP
Kavvson

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Best answers
0
Reaction score
72
Location
Poland
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.
 

PineIt

Web Developer
Joined
Sep 9, 2010
Messages
50
Best answers
0
Reaction score
4
Thank you for the kind words! You do that; I'm around.
 
OP
Kavvson

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Best answers
0
Reaction score
72
Location
Poland
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" />
 

PineIt

Web Developer
Joined
Sep 9, 2010
Messages
50
Best answers
0
Reaction score
4
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 />';
 
OP
Kavvson

Kavvson

Gdy boli cie glowa wez
Joined
Jun 25, 2008
Messages
1,177
Best answers
0
Reaction score
72
Location
Poland
And what about saving all the fields? Look here

 
Top