PDA

View Full Version : Need some direction with this script



itivae
03-13-2013, 08:23 PM
Hi i am writing a script to check a guid against a column in a database. Here is what I have so far but I keep getting a "Parse error: syntax error, unexpected T_STRING in /home/mydir/foobar/guid-checker.php on line 39"


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>guid check</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
require_once('connectvars.php');

$player_name = 'itivae'; //$_POST['playername'];
$player_id = '1010103'; //$_POST['playerid'];
$guid = '4e72f140c35df55909ce551273c44006'; //$_POST['guid'];

/*if(!isset($_POST['playernam']) ||
!isset($_POST['playerid']) ||
!isset($_POST['guid']) || {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}*/
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$query = "SELECT banned_guid, player_id, player_name FROM player_data WHERE banned_guid = $guid;

if ($result = $mysqli->query($query)) {

if (mysql_num_rows($result)>0) {
printf ('Unapproved ' . $guid . ' ' . 'matches a guid on the ban list.');
}
}

else {


$query ="INSERT INTO player_data (player_name, player_id, guid)
VALUES ('itivae', '1010103', '4e72f140c35df55909ce551273c44006')";
echo 'This player ' . $player_name. ' ' . $player_id . ' ' . $guid . ' has been added to the whitelist.');
}

$mysqli->close();

?>
</body>
</html>


Any help is appreciated. I may not even be going about this in the right manner as I am still new with php.

Thanks in advance.

Beverleyh
03-13-2013, 08:58 PM
Here's some info on what that error means and how to fix it: http://www.ehow.com/info_8717984_php-syntax-error-unexpected-string.html

You'll need an editor with line numbering to make finding the problem easier - PSPad http://www.pspad.com/ and Notepad++ http://notepad-plus-plus.org/ are both free ones that should help, so open the guid-checker.php file in one of those and check line 43.

itivae
03-13-2013, 09:13 PM
Hi Beverleyh,

Thanks for the information. I have removed a great deal of the code (in an attempt to get at least part of it working correctly so that I have something to work off of), I am still getting a T_STRING error but now it is past the last line of code. I cannot see any glaring syntax errors (but maybe I have become blind to them after several hours).

Here is the code I am working with:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>guid check</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
require_once('connectvars.php');

$player_name = 'itivae'; //$_POST['playername'];
$player_id = '1010103'; //$_POST['playerid'];
$guid = '4e72f140c35df55909ce551273c44006'; //$_POST['guid'];

/*if(!isset($_POST['playernam']) ||
!isset($_POST['playerid']) ||
!isset($_POST['guid']) || {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}*/
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$query = "SELECT banned_guid, player_id, player_name FROM player_data WHERE banned_guid = $guid";

if ($result = $mysqli->query($query)) {

if (mysql_num_rows($result)>0) {
printf ('Unapproved ' . $guid . ' ' . 'matches a guid on the ban list.');
}
}

else {
echo 'This worked';
}


$mysqli->close();


?>
</body>
</html>

itivae
03-13-2013, 09:31 PM
Oh *&%(*%(.....There is a missing " on line 41. Thanks for the help. I am going to leave this thread open for a minute in case I have another problem.

itivae
03-13-2013, 11:39 PM
So I have played with this a little more. Its seems to run but it is not accomplishing all of its tasks. It skips the first if statment and always evaluates to true making the "else" statment always run even when its false. I was hoping somone might have an idea of what I am doing wrong. Here is the displayed text:
"Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/userdir/foobar/guid-checker.php on line 31
This player itivae 1010103 4e72f140c35df55909ce551273c44006 has been added to the whitelist.

Here is the current code


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>guid check</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
require_once('connectvars.php');

$player_name = 'itivae'; //$_POST['playername'];
$player_id = '1010103'; //$_POST['playerid'];
$guid = '4e72f140c35df55909ce551273c44006'; //$_POST['guid'];

/*if(!isset($_POST['playernam']) ||
!isset($_POST['playerid']) ||
!isset($_POST['guid']) || {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}*/
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$query = "SELECT banned_guid FROM player_bans WHERE banned_guid = $guid";

$result = $mysqli->query($query);

if (mysql_num_rows($result)>0){

printf ('Unapproved ' . $guid . ' ' . 'matches a guid on the ban list.');

}


else {



$query ="INSERT INTO player_data (player_name, player_id, guid) VALUES ('itivae', '1010103', '4e72f140c35df55909ce551273c44006')";
echo 'This player ' . $player_name. ' ' . $player_id . ' ' . $guid . ' has been added to the whitelist.';
}

$mysqli->close();

?>
</body>
</html>



This always runs the else text but does not INSERT anything into the player_data table.

Thanks

traq
03-13-2013, 11:41 PM
Speaking of editors, you'd do well to choose one with syntax highlighting. It makes a world of difference.

I changed your posts above to use [PHP] tags instead of simple [CODE] tags - as you can see, the error becomes very obvious. :)

itivae
03-13-2013, 11:49 PM
Pardon my ignorance but could you please be a little more specific?

djr33
03-14-2013, 12:19 AM
Compare the good code and the bad code, paying close attention to the red parts. Look for patterns. With some practice you'll see it very quickly.

traq
03-14-2013, 01:30 AM
Text editors desgined for coding (or simply to accommodate coding) highlight different parts of your code in different ways, to help distinguish them. It's much easier to have everything color-coded than to stare at a long line of black-and-white gibberish, looking for a missing double-quote. The syntax highlighting used by the forum's [PHP] tags, for example, makes string values red, variable names blue, function names green, comments yellow, etc.:
<?php

$thisIsAVariable = "this is a string";

/* this is a comment */
thisIsAFunction( $thisIsAVariable );

Now, if you'd forgotten the closing double-quote on your string, you'd get a fatal error (something like "unexpected $end," in this case). But you'd be able to find the problem almost instantly, because you'd notice that your string was much larger than you intended it to be:
<?php

$thisIsAVariable = "this is a string;

/* this is a comment */
thisIsAFunction( $thisIsAVariable );

cool, huh?

itivae
03-14-2013, 01:34 AM
Alright I have been staring at this for more than an hour.... I have tried to rearrange the code. I am really stumped. Here is my current code....Feel free to hint at the answers...



<?php
require_once('connectvars.php');

$player_name = 'itivae'; //$_POST['playername'];
$player_id = '1010103'; //$_POST['playerid'];
$guid = '4e72f140c35df55909ce551273c44007'; //$_POST['guid'];

/*if(!isset($_POST['playernam']) ||
!isset($_POST['playerid']) ||
!isset($_POST['guid']) || {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}*/
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s \n", $mysqli->connect_error);
exit();
}
$query = "SELECT * FROM player_bans WHERE banned_guid='$guid'";

$result = $mysqli->query($query);


if (mysql_num_rows($result)<1){
$query = "INSERT INTO player_data (player_name, player_id, guid) VALUES ('itivae', '1010103', '4e72f140c35df55909ce551273c44007')";
echo 'This player ' . $player_name . ' ' . $player_id . ' ' . $guid . ' has been added to the whitelist.';

}


else {

echo 'Unapproved ' . $guid . ' matches a guid on the ban list.';


}
$mysqli->close();

?>


Am I any closer? Do I need to look at the db connection closer? It seems to not trigger the error message so I am assuming it is connected (you know what they say about assumptions though). These are two separate tables I don't think I need a new connection for each db update but like I said I am not overly proficient with php and MySQL. Also on the INSERT INTO line is there supposed to be any syntax between the definition of the columns and the values inserted into the columns? From what I have read that string seems acceptable. Thanks for taking the time.

traq
03-14-2013, 01:46 AM
Is this still the warning you get?
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/userdir/foobar/guid-checker.php on line ...

mysqli_query() (http://php.net/mysqli.query) returns a mysqli_result object if the query is successful, but returns boolean FALSE if there was a problem. Since you don't check, you're ending up passing FALSE to mysqli_num_rows() (http://php.net/mysqli_result.num_rows), when it expects the object - hence, your error message.


/* snip */
$result = $mysqli->query($query);

# right about here, you should be checking if the query was successful or not.

if (mysql_num_rows($result)<1){
/* snip */

djr33
03-14-2013, 01:49 AM
Looks like it's mixing mysqli and mysql. Is that ok?

traq
03-14-2013, 02:01 AM
Looks like it's mixing mysqli and mysql. Is that ok?

I did not notice that. Nope, not okay, won't work. itivae, you're missing an i in mysqli_num_rows().

However, that's not what's causing this particular error. You still need to be checking if your query was successful before trying to use it. I would also suggest not mixing object-oriented (e.g., $mysqli->query()) and procedural (e.g., mysqli_num_rows()) styles - choose one or the other.

Beverleyh
03-14-2013, 06:36 AM
Speaking of editors, you'd do well to choose one with syntax highlighting. It makes a world of difference.

I changed your posts above to use [PHP] tags instead of simple [CODE] tags - as you can see, the error becomes very obvious. :)
PSPad http://www.pspad.com/ and Notepad++ http://notepad-plus-plus.org/ as suggested earlier, both have syntax highlighting :)

itivae
03-14-2013, 10:50 PM
Thanks for the suggestions. I use several text editors that all have syntax highlighting. I have made some headway on this code but am running into a problem when I try to INSERT data into the database. I have tried using mysqli_query() but I am not getting the confirmation or the error text. Just a blank screen. I have commented on the point that the code works till. Any suggestions would be much appreciated.


<?php
require_once('connectvars.php');
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s \n", $mysqli->connect_error);
exit();
}

$player_name = 'itivae'; //$_POST['playername'];
$player_id = '1010103'; //$_POST['playerid'];
$guid = '4e72f140c35df55909ce551273c44007'; //$_POST['guid'];

/*if(!isset($_POST['playernam']) ||
!isset($_POST['playerid']) ||
!isset($_POST['guid']) || {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}*/



$query = "SELECT * FROM player_bans WHERE banned_guid = '$guid'";


if ($result = $mysqli->query($query)){
while ($obj = $result->fetch_object()) {

printf ('<div class="bans">'."%s", $obj->banned_guid);
printf (" appears in the ban list" . '</div>');
}
} //WORKS TILL HERE

else {

$query = "INSERT INTO player_data (player_name, player_id, guid)
VALUES ('$player_name', '$player_id', '$guid')";
$result = $mysqli->query($query);
if ( false===$result ) {
printf("error: %s\n", mysqli_error($mysqli));
}
else {
echo 'Player: ' . $player_name . ' ' . $player_id . ' ' . $guid . ' has been added to the whitelist.';
}

}
$mysqli->close();

?>

traq
03-14-2013, 11:21 PM
... but I am not getting the confirmation or the error text. Just a blank screen.

That is almost always an indication that there was an error, and that your server is configured to prevent display of the error message.

This is fairly common with web hosting companies. You need to adjust your error reporting settings in your php.ini file, find your server's error log, and/or talk to your web host about how to do so.

djr33
03-14-2013, 11:25 PM
Specifically, it is a parse error-- nothing is displayed because there is a problem understanding the code, so nothing is displayed. (Runtime errors, those found when trying to execute the script, are less severe and will show you at least some content-- a parse error stops the script from executing at all.)

Most frequently parse errors come from a missing ; or ) or }, but there can be other reasons too.

itivae
03-14-2013, 11:50 PM
Specifically, it is a parse error-- nothing is displayed because there is a problem understanding the code, so nothing is displayed. (Runtime errors, those found when trying to execute the script, are less severe and will show you at least some content-- a parse error stops the script from executing at all.)

Most frequently parse errors come from a missing ; or ) or }, but there can be other reasons too.

But other parse errors where returned as a message....does that mean that some do and some dont? I have spoken with my host and it looks like error_reporting is fully enabled..... I am still getting a blank screen..... Any other thoughts?

djr33
03-15-2013, 12:10 AM
Are you certain they were parse errors, not runtime errors? The error messages look very similar, but the first word will be different.

If you want to test it, you can try to run this as a new .php file:

<?php if( ?>

When I run that, I get the following error:

Parse error: syntax error, unexpected ';' in /home/.../test.php on line 1

If you get that error, it means you have error reporting enabled. If not, there is a problem with error reporting.





Edit: on an unrelated note, that's a weird error. I wonder why it claims there is a ';' when there isn't one in the code at all. Traq, any ideas?
I suppose it really means "the end came too early", and it's just not phrased well.
PHP has some weird error messages (but you learn to understand them with time). One of them (in the English version of PHP) is actually written in Indonesian-- some kind of weird typo!

itivae
03-15-2013, 12:14 AM
when I run that as a new .php file I get the following error:


Parse error: syntax error, unexpected ';' in /home/userdir/foobar/errortest.php on line 1

djr33
03-15-2013, 12:43 AM
Hm. I wonder if that's an infinite loop. Add echo 1; inside the loop-- if you get thousands of 1s, then you know it's an infinite loop that times out after probably 30 seconds (depending on server settings).

By the way:

died('We are sorry, but there appears to be a problem with the form you submitted.'); Should be die, not died. (Technically it's exit 'Message'. The other forms are aliases, which work but aren't standard. That's not too important though.)
But that's in a comment so it shouldn't cause you any problems at the moment.

traq
03-15-2013, 03:15 AM
on an unrelated note, that's a weird error. I wonder why it claims there is a ';' when there isn't one in the code at all. Traq, any ideas?
I suppose it really means "the end came too early", and it's just not phrased well.
I get Parse error: syntax error, unexpected '?>' ... - but I'm running 5.4. I would suspect that the ?> was simply synonymous with ; in earlier versions (since you can omit the semicolon -can, not should :)- in single-line statements), or, at least, resolved to the same error message.


PHP has some weird error messages (but you learn to understand them with time). One of them (in the English version of PHP) is actually written in Indonesian-- some kind of weird typo![/i]
Are you thinking of paamayim_nekudotayim? It's Hebrew (it means "double-colon").



//WORKS TILL HERE
else {
$query = "INSERT INTO player_data (player_name, player_id, guid)
VALUES ('$player_name', '$player_id', '$guid')";
$result = $mysqli->query($query);
if ( false===$result ) {
printf("error: %s\n", mysqli_error($mysqli));
}
else {
echo 'Player: ' . $player_name . ' ' . $player_id . ' ' . $guid . ' has been added to the whitelist.';
}
}
$mysqli->close();
?>

That parses fine for me...

Try adding this immediately after you run the INSERT query:
print '<pre>'; exit( var_dump( $result ) );

djr33
03-15-2013, 03:32 AM
Are you thinking of paamayim_nekudotayim? It's Hebrew (it means "double-colon").Yeah, that's the one. Hebrew, not Indonesian. I'll remember that.

Ok, back to the topic, I'll stop being off topic :)

itivae
03-15-2013, 04:48 AM
That parses fine for me...

Try adding this immediately after you run the INSERT query:
print '<pre>'; exit( var_dump( $result ) );

I still get a blank screen with this added in. i.e.
else {

$query = "INSERT INTO player_data (player_name, player_id, guid)
VALUES ('$player_name', '$player_id', '$guid')";
print '<pre>'; exit( var_dump( $result ) );
$result = $mysqli->query($query);
if ( false===$result ) {
printf("error: %s\n", mysqli_error($mysqli));
}
else {
echo 'Player: ' . $player_name . ' ' . $player_id . ' ' . $guid . ' has been added to the whitelist.';
}

}
$mysqli->close();

?>

itivae
03-15-2013, 04:55 AM
Hm. I wonder if that's an infinite loop. Add echo 1; inside the loop-- if you get thousands of 1s, then you know it's an infinite loop that times out after probably 30 seconds (depending on server settings).



the result for this code:
else {
echo "1";
$query = "INSERT INTO player_data (player_name, player_id, guid)
VALUES ('$player_name', '$player_id', '$guid')";

$result = $mysqli->query($query);
if ( false===$result ) {
printf("error: %s\n", mysqli_error($mysqli));
}
else {
echo 'Player: ' . $player_name . ' ' . $player_id . ' ' . $guid . ' has been added to the whitelist.';
}

}
$mysqli->close();

?>

else {

$query = "INSERT INTO player_data (player_name, player_id, guid)
VALUES ('$player_name', '$player_id', '$guid')";

$result = $mysqli->query($query);
if ( false===$result ) {echo "1";
printf("error: %s\n", mysqli_error($mysqli));
}
else {
echo 'Player: ' . $player_name . ' ' . $player_id . ' ' . $guid . ' has been added to the whitelist.';
}

}
$mysqli->close();

?>[/PHP]

and


else {
$query = "INSERT INTO player_data (player_name, player_id, guid)
VALUES ('$player_name', '$player_id', '$guid')";

$result = $mysqli->query($query);
if ( false===$result ) {
printf("error: %s\n", mysqli_error($mysqli));
}
else {echo "1";
echo 'Player: ' . $player_name . ' ' . $player_id . ' ' . $guid . ' has been added to the whitelist.';
}

}
$mysqli->close();

?>
Is still a blank screen. Both have been run with

echo 1;

and
echo "1";

Am I using it correctly?

djr33
03-15-2013, 05:53 AM
I was talking about the while loop above that. Is it possible that loop is never stopping?

itivae
03-15-2013, 06:20 AM
Sorry my mistake. Still blank with this code.


if ($result = $mysqli->query($query)){
while ($obj = $result->fetch_object()) {
echo '1';
printf ('<div class="bans">'."%s", $obj->banned_guid);
printf (" appears in the ban list" . '</div>');
}
} //WORKS TILL HERE

djr33
03-15-2013, 06:22 AM
//WORKS TILL HERE That doesn't make sense. It can't be blank if it "works" until that point-- you should see a lot of 1s. Back up (keep moving the echo line up the code) until you find where it actually works. Start at the top to be sure it's doing something. If not, it's a parse error and somehow this page is different than the other one.

itivae
03-15-2013, 06:41 AM
This is what I get


$query = "SELECT * FROM player_bans WHERE banned_guid = '$guid'";

echo '1'; //here echos 1 once
if ($result = $mysqli->query($query)){echo '1'; //here echos 1 once
while ($obj = $result->fetch_object()) {

printf ('<div class="bans">'."%s", $obj->banned_guid);
printf (" appears in the ban list" . '</div>');
}

} //WORKS TILL HERE


here it it gives this "Parse error: syntax error, unexpected T_ELSE in /home/userdirfoobar/guid-checker.php on line 35" 35 is the line where the else{} begins.

if ($result = $mysqli->query($query)){
while ($obj = $result->fetch_object()) {

printf ('<div class="bans">'."%s", $obj->banned_guid);
printf (" appears in the ban list" . '</div>');
}

} //WORKS TILL HERE
echo '1';
else {

$query = "INSERT INTO player_data (player_name, player_id, guid)
VALUES ('$player_name', '$player_id', '$guid')";

$result = $mysqli->query($query);
if ( false===$result ) {
printf("error: %s\n", mysqli_error($mysqli));

djr33
03-15-2013, 06:58 AM
Ok, good. Parse errors are displaying. You can't interrupt if (...) {...} else {....} with something before 'else'. But try it in some other places. You should be able to figure out exactly where it breaks then work out why. I suggest starting a the top of your script first, then jumping down a bit, and continue until it doesn't work (until you don't see any 1s). Then go back to find the exact spot. That's how debugging works, and, yes, it can take a while.

itivae
03-15-2013, 06:23 PM
So I am making progress slowly but surely (in a great part due to the advice received here, so thanks for that). I currently have some error checking working and the script is INSERT ing the data into my database. I need to make sure that duplicate data is not entered into the database as well and have been looking at these SQL syntax options to accomplish it (INSERT...IGNORE, INSERT...ON DUPLICATE KEY UPDATE, and REPLACE INTO) does it really matter which I use or is there a better way?

Here is my current code


<?php
require_once('connectvars.php');
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s \n", $mysqli->connect_error);
exit();
}

$player_name = 'itivae'; //$_POST['playername'];
$player_id = '10101038'; //$_POST['playerid'];
$guid = '4e72f140c35df55909ce551273c44007'; //$_POST['guid'];

/*if(!isset($_POST['playername']) ||
!isset($_POST['playerid']) ||
!isset($_POST['guid']) || {
die('We are sorry, but there appears to be a problem with the form you submitted.');
}*/

if(mb_strlen($guid)<32){
echo 'the guid checked is less than 32 characters';
}
if(mb_strlen($guid)>32){
echo 'the guid checked is more than 32 characters';
}
if(mb_strlen($player_id)<8){
echo ' the player_id you entered is less than 8 characters';
}
if(mb_strlen($player_id)>8){
echo ' the player_id you entered is more than 8 characters';
}
if(mb_strlen($guid)==32 && mb_strlen($player_id)==8){

$query = "SELECT * FROM player_bans WHERE banned_guid = '$guid'";


if ($result = $mysqli->query($query)){
while ($obj = $result->fetch_object()) {

printf ('<div class="bans">'."%s", $obj->banned_guid);
printf (' appears in the ban list' . '</div>');
$mysqli->close();
exit;
}

}



$q = "INSERT INTO player_data (player_name, player_id, guid)
VALUES ('$player_name', '$player_id', '$guid')";

//Should I duplicate check here?

if($r = $mysqli->query($q)) {

//or here?

echo 'Player: ' . $player_name . ' ' . $player_id . ' ' . $guid . ' has been added to the whitelist.';

}
else {
printf("error: %s\n", mysqli_error($mysqli));

}


}
$mysqli->close();

?>

Thanks

itivae
03-15-2013, 07:24 PM
I used this


$duplicateResult=$mysqli->query("SELECT `player_name`,`player_id`,`guid` FROM `player_data` WHERE `player_name`='$player_name' OR `player_id`='$player_id' OR `guid`='$guid'");
if($duplicateResult->num_rows>=1) {

echo 'Some of the information already exists in the database';
$mysqli->close();
exit;

}

but I am having trouble if the duplicate message is triggered


<?php
require_once('connectvars.php');
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s \n", $mysqli->connect_error);
exit();
}

$player_name = 'itivae'; //$_POST['playername'];
$player_id = '10101038'; //$_POST['playerid'];
$guid = '4e72f140c35df55909ce551273c44007'; //$_POST['guid'];

/*if(!isset($_POST['playername']) ||
!isset($_POST['playerid']) ||
!isset($_POST['guid']) || {
die('We are sorry, but there appears to be a problem with the form you submitted.');
}*/

if(mb_strlen($guid)<32){
echo 'the guid checked is less than 32 characters';
}
if(mb_strlen($guid)>32){
echo 'the guid checked is more than 32 characters';
}
if(mb_strlen($player_id)<8){
echo ' the player_id you entered is less than 8 characters';
}
if(mb_strlen($player_id)>8){
echo ' the player_id you entered is more than 8 characters';
}
if(mb_strlen($guid)==32 && mb_strlen($player_id)==8){

$query = "SELECT * FROM player_bans WHERE banned_guid = '$guid'";


if ($result = $mysqli->query($query)){
while ($obj = $result->fetch_object()) {

printf ('<div class="bans">'."%s", $obj->banned_guid);
printf (' appears in the ban list' . '</div>');
$mysqli->close();
exit;
}

}


$duplicateResult=$mysqli->query("SELECT `player_name`,`player_id`,`guid` FROM `player_data` WHERE `player_name`='$player_name' AND `player_id`='$player_id' AND `guid`='$guid'");
if($duplicateResult->num_rows>=1) {

echo 'Some of the information already exists in the database';
$mysqli->close();
exit;

}


$q = "INSERT INTO player_data (player_name, player_id, guid)
VALUES ('$player_name', '$player_id', '$guid')";

if($r = $mysqli->query($q)) {

echo 'Player: ' . $player_name . ' ' . $player_id . ' ' . $guid . ' has been added to the whitelist.';

}

}


$mysqli->close();

?>