Error in PHPmyAdmin. What can I do?

Status
Not open for further replies.

t.miedema30

New Member
Messages
4
Reaction score
0
Points
0
I make games with a program called gamemaker. Now I use Netread.dll to connect to a MySQL database. With this .dll came a php script I had to upload and execute on the MySQL database.

I click on the Import button (is that right?) and select the .php . I get this error:

Fout
Er schijnt een fout te zitten in uw SQL-query. Mocht de MySQL-server een foutmelding hebben terug gegeven, probeer dan of u hiermee uw fout kunt oplossen.

ERROR: Onbekende Punctuatie String @ 1
STR: <?
SQL: <?php
/*
Before using this engine create this table:

CREATE TABLE `users` (
`username` varchar(255) collate latin1_general_ci NOT NULL,
`password` varchar(255) collate latin1_general_ci NOT NULL,
`score` int(255) NOT NULL,
`room` int(255) NOT NULL,
`x` int(255) NOT NULL,
`y` int(255) NOT NULL,
`ban` int(255) NOT NULL,
`online` int(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

*/

//this is here for security reasons
foreach($_POST as $key => $val) {
$_POST[$key] = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES)));

SQL-query:

<?php /* Before using this engine create this table: CREATE TABLE `users` ( `username` varchar(255) collate latin1_general_ci NOT NULL, `password` varchar(255) collate latin1_general_ci NOT NULL, `score` int(255) NOT NULL, `room` int(255) NOT NULL, `x` int(255) NOT NULL, `y` int(255) NOT NULL, `ban` int(255) NOT NULL, `online` int(255) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; */ //this is here for security reasons foreach($_POST as $key => $val) { $_POST[$key] = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES)));

MySQL retourneerde:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<?php
/*
Before using this engine create this table:

CREATE TABLE `users` (' at line 1
------------------------------------------------------------------------------
(I'm sorry some things are in dutch)
(I have this code from a free to use tutorial)

The original .php file:
--------------------------------------------------------------------------------------
<?php
/*
Before using this engine create this table:

CREATE TABLE `users` (
`username` varchar(255) collate latin1_general_ci NOT NULL,
`password` varchar(255) collate latin1_general_ci NOT NULL,
`score` int(255) NOT NULL,
`room` int(255) NOT NULL,
`x` int(255) NOT NULL,
`y` int(255) NOT NULL,
`ban` int(255) NOT NULL,
`online` int(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

*/

//this is here for security reasons
foreach($_POST as $key => $val) {
$_POST[$key] = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES)));
$$key = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES)));
}
foreach($_GET as $key => $val) {
$_GET[$key] = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES)));
$$key = stripslashes(strip_tags(htmlspecialchars($val, ENT_QUOTES)));
}

$sqlhost = "localhost"; //mysql host (usually localhost)
$sqluser = "**********"; //mysql username
$sqlpass = "*********"; //mysql password
$sqldb = "database_name"; //mysql database name

$connect = mysql_connect($sqlhost,$sqluser,$sqlpass) or die ("0"); //connect to the server or give a server error
mysql_select_db ($sqldb); //connect to the database

$act = $_GET["act"]; //get the action that the game or user is doing

//register
/*
http://mysite-tm.x10.mx/public_ftp/game.php?act=reg&user=username&pass=password
*/
function register() {
$user = $_GET["user"]; //username that the game provides
$pass = $_GET["pass"]; //password that the game provides
$regcheck = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username='$user'")); //mysql query checking if the user exists
if ($regcheck) {
die("1"); //tell the game that the username is taken
}
$register = mysql_query("INSERT INTO users (`username`,`password`,`score`,`room`,`x`,`y`) VALUES ('$user','$pass','0','1','50','50')"); //since the username was not taken we will insert values into the mysql table (change the room number, x, and y to what you want)
if ($register) {
echo("2"); //tell the game that the registration was successful
} else {
die("0"); //tell the game there was an error with the server
}
}

//login
/*
http://mysite-tm.x10.mx/public_ftp/game.php?act=log&user=username&pass=password
*/
function login() {
$user = $_GET["user"]; //username that the game provides
$pass = $_GET["pass"]; //password that the game provides
$login = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username='$user' and password='$pass' and online='0'")); //mysql query checking: if the username exists, if the passwords match, and if the user is already online
if ($login) { //username exists, password is correct, and user is not online
$online = mysql_query("UPDATE users SET online = '1' WHERE username='$user' and password='$pass'");
if ($online) {
$query = mysql_query("SELECT * FROM users WHERE username='$user' and password='$pass'"); //tell the game that we are now logged in and send over the player's score, room, x, and y
while ($stats = mysql_fetch_assoc($query)) {
echo ("score = $stats[score]; global.proom = $stats[room]; global.px = $stats[x]; global.py = $stats[y];"); //the variables that are being sent
}
} else {
die("0"); //tell the game there was an error with the server
}
} else {
//tell the game one of these errors:
//user is already online
//username doesn't exist
//password does not match the one with the username
die("3");
}
}

//save
/*
http://mysite-tm.x10.mx/public_ftp/game.php?act=sav&user=username&pass=password&score=400&room=2&x=20&y=40
*/
function save() {
$user = $_GET["user"]; //username that the game provides
$pass = $_GET["pass"]; //password that the game provides
$score = $_GET["score"]; //score that the game provides
$room = $_GET["room"]; //room that the game provides
$x = $_GET["x"]; //x that the game provides
$y = $_GET["y"]; //y that the game provides
$savuser = mysql_query("UPDATE users SET score='$score',room='$room',x='$x',y='$y' WHERE username='$user' and password='$pass' and online='1'"); //mysql query that takes all of the values sent by the game and puts them into the table
if ($savuser) {
echo("4"); //tell the game that the save was a success
} else {
die("0"); //tell the game there was an error with the server
}
}

//logout
/*
http://mysite-tm.x10.mx/public_ftp/game.php?act=out&user=username&pass=password
*/
function logout() {
$user = $_GET["user"]; //username that the game provides
$pass = $_GET["pass"]; //password that the game provides
$logout = mysql_query("UPDATE users SET online = '0' WHERE username='$user' and password='$pass'"); //mysql query that updates whether the user is online
if ($logout) {
echo("5"); //tell the game that the logout was a success
} else {
die("0"); //tell the game there was an error with the server
}
}

//signature
/*
http://mysite-tm.x10.mx/public_ftp/game.php?act=sig&user=username
*/
function sig() {
header("Content-type: image/png"); //this lines tells the browers that the PHP file is a PNG image
$user = $_GET["user"]; //username to display on the signature
$img = imagecreate(150, 28); //makes an image that is 150 pixels wide by 28 high pixels
$black = imagecolorallocate($img,0,0,0); //makes the background color black
$white = imagecolorallocate($img,255,255,255); //the color white (used for text)
//if you want to change the text or backgroud color then re-enter the RGB values
imagestring($img,1,1,0,"Name of your game",$white); //draws the text "Name of your game" (the first number is the size of the text, the second is the x position of the text, the third is the y position of the text)
$statsq = mysql_query("SELECT * FROM users WHERE username='$user'") or die("ERROR"); //mysql query to get * (meaning anyting) from the table where the username is $user
while ($stats = mysql_fetch_assoc($statsq)) {
imagestring($img,1,1,10,"Username: $stats[username]",$white); //draws the players username
imagestring($img,1,1,20,"Score: $stats[score]",$white); //draws the players score
}
imagepng($img); //draws the whole image as a PNG
imagedestroy($img); //destroys the whole image
}

//scores
/*
http://mysite-tm.x10.mx/public_ftp/game.php
*/
function scores() {
$scoresq = mysql_query("SELECT * FROM users ORDER BY score DESC LIMIT 5") or die("ERROR"); //mysql query that gets * from the table, displays them in descending order, and limits the amount to show to 5
echo ("<table><tr><td align='center'><b>Name</b></td><td align='center'><b>Score</b></td></tr>"); //makes the start of the table
while ($scores = mysql_fetch_assoc($scoresq)) {
echo ("<tr><td align='center' style='font-color: white;'>".$scores["username"]."</td>
<td align='center' style='font-color: white;'>".$scores["score"]."</td></tr>"); //makes the username and score show
}
echo ("</table>"); //makes the end of the table
}

//what is the game or user doing?
switch ($act) {
case "reg": register(); break; //if the game is registering
case "log": login(); break; //if the game is logging in
case "sav": save(); break; //if the game is saving
case "out": logout(); break; //if the game is logging out
case "sig": sig(); break; //displays a signature
default: scores(); break; //this is the default page (displays scores)
}
?>


THANKS

thijsmie
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
Please edit your post and add [CODE ][/CODE] tags around the code. This will make the post easier on the eyes and support will be better.
 
Last edited:

Skizzerz

Contributors
Staff member
Contributors
Messages
2,928
Reaction score
118
Points
63
in phpmyadmin, click on the database you want to use for your site in the left hand bar. Then, click on the little icon in the upper left that has "SQL" inside of a box. This will open up a new browser window with a textbox in it.

Inside of the textbox, copy/paste the following and submit:
Code:
CREATE TABLE `users` (
`username` varchar(255) collate latin1_general_ci NOT NULL,
`password` varchar(255) collate latin1_general_ci NOT NULL,
`score` int(255) NOT NULL,
`room` int(255) NOT NULL,
`x` int(255) NOT NULL,
`y` int(255) NOT NULL,
`ban` int(255) NOT NULL,
`online` int(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
Status
Not open for further replies.
Top