Mysql cominuceren met Game-maker - Data base maken

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Top Low-Code Developer Gezocht!

Bedrijfsomschrijving Unieke Kansen, Uitstekende Arbeidsvoorwaarden & Inspirerend Team Wij zijn een toonaangevende, internationale organisatie die de toekomst van technologie vormgeeft door het creëren van innovatieve en baanbrekende oplossingen. Ons succes is gebaseerd op een hecht en gepassioneerd team van professionals die altijd streven naar het overtreffen van verwachtingen. Als jij deel wilt uitmaken van een dynamische, vooruitstrevende en inspirerende werkomgeving, dan is dit de perfecte kans voor jou! Functieomschrijving Als Low-Code Developer ben je een cruciaal onderdeel van ons team. Je werkt samen met collega's uit verschillende disciplines om geavanceerde applicaties te ontwikkelen en te optimaliseren met behulp van Low-code

Bekijk vacature »

Pagina: 1 2 volgende »

Huppelpup php

huppelpup php

20/04/2011 19:27:37
Quote Anchor link
Hey,

Ik wil met game maker gegevens opslaan op mijn website. Ze zeiden dat ik hier moest zijn. Ik heb een website aan gemaakt... Maar ze zeiden dat ik een database moest maken in mysql. Nu is mijn probleem hoe maak ik die aan en hoe kom ik achter de naam van de database, en hoe maak ik dat aan?
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<html>
<head>
</head>
<body>
<?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 = "naam_van_je_mysql_account"; //mysql username
$sqlpass = "wachtwoord"; //mysql password
$sqldb = "database_naam"; //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://yoururl.com/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://yoururl.com/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://yoururl.com/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://yoururl.com/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://yoururl.com/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://yoururl.com/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)
}
?>

</body>
</html>
[/code=php]
Gewijzigd op 20/04/2011 19:49:33 door Huppelpup php
 
PHP hulp

PHP hulp

24/04/2024 11:26:11
 
Noppes Homeland

Noppes Homeland

20/04/2011 19:45:11
Quote Anchor link
Waarom post je code bij een vraag die hieraan niet gerelateerd is.

Maar als je wilt weten of deze code goed is, dan kan ik je vertellen dat het bagger code is.

Maar ja nu je vraag, die is niet te beantwoorden zolang jij ons niet informeert of dat je het op een eigen webserver gaat draaien of dat je je te maken hebt met een hoster die wel dan niet mysql aanbied.
 
Huppelpup php

huppelpup php

20/04/2011 19:48:35
Quote Anchor link
Ik draai geen eigen webserver, mijn host is x10hosting. kan je nu mijn vraag beantwoorden?
 
- Ariën  -
Beheerder

- Ariën -

20/04/2011 19:49:35
Quote Anchor link
Uiteraard weten we de naam van je database niet, die moet jezelf even achterhalen.
Kan zijn dat je die moet aanmaken in je control panel, en anders moet je even je hosting contacteren.

Als je een eigen server draait, dan kan je met phpMyAdmin een database aanmaken.
 
Huppelpup php

huppelpup php

20/04/2011 19:54:44
Quote Anchor link
www.game-base.x10.mx/oefen/Naamloos.png
waar kan ik zo'n database aan maken?
 
Wesley PHP

Wesley PHP

20/04/2011 19:57:50
Quote Anchor link
Huppelpup php op 20/04/2011 19:54:44:
www.game-base.x10.mx/oefen/Naamloos.png
waar kan ik zo'n database aan maken?


Die moet je niet aanmaken in filemanager, maar in PHPMyAdmin (Als je die hebt).
 
Huppelpup php

huppelpup php

20/04/2011 20:03:27
Quote Anchor link
In mijn cpanel staat onder database phpMyadmin. Maar dan moet ik in loggen en mijn w8woord voor de cpanel zelf werktniet, moet ik dan een apart account aanmaken en waar? hij geeft deze error als ik probeer inteloggen met mijn cpanel gegevens #1045 Kan niet inloggen op de MySQL-server

wat moet ik doen?

Toevoeging op 20/04/2011 20:03:28:

In mijn cpanel staat onder database phpMyadmin. Maar dan moet ik in loggen en mijn w8woord voor de cpanel zelf werktniet, moet ik dan een apart account aanmaken en waar? hij geeft deze error als ik probeer inteloggen met mijn cpanel gegevens #1045 Kan niet inloggen op de MySQL-server

wat moet ik doen?
 
Wesley PHP

Wesley PHP

20/04/2011 20:06:57
Quote Anchor link
Maak is een print screen van de dingen waar je uit kan kiezen.
 
Huppelpup php

huppelpup php

20/04/2011 20:09:48
Quote Anchor link
Wesley PHP op 20/04/2011 20:06:57:
Maak is een print screen van de dingen waar je uit kan kiezen.


www.game-base.x10.mx/oefen/Naamloos.png

is dit goed?
 
Wesley PHP

Wesley PHP

20/04/2011 20:12:45
Quote Anchor link
Je moet eerst een MySQL Database aanmaken, en probeer dan de phpMyAdmin is.
 
Huppelpup php

huppelpup php

20/04/2011 20:13:56
Quote Anchor link
Wesley PHP op 20/04/2011 20:12:45:
Je moet eerst een MySQL Database aanmaken, en probeer dan de phpMyAdmin is.


welke moet ik dan gebruiken?
 
Wesley PHP

Wesley PHP

20/04/2011 20:16:08
Quote Anchor link
MySQL Database de eerste, als je dat bedoelt.
 
Huppelpup php

huppelpup php

20/04/2011 20:18:08
Quote Anchor link
Wesley PHP op 20/04/2011 20:16:08:
MySQL Database de eerste, als je dat bedoelt.


ja thx ik kan nu inloggen op phpmyadmin maar krijg een wit beeld...

Toevoeging op 20/04/2011 20:18:11:

Wesley PHP op 20/04/2011 20:16:08:
MySQL Database de eerste, als je dat bedoelt.


ja thx ik kan nu inloggen op phpmyadmin maar krijg een wit beeld...
 
Wesley PHP

Wesley PHP

20/04/2011 20:18:47
Quote Anchor link
Dus alleen wit? Misschien refreshen?
 
Huppelpup php

huppelpup php

20/04/2011 20:20:36
Quote Anchor link
Wesley PHP op 20/04/2011 20:18:47:
Dus alleen wit? Misschien refreshen?


ja alleen wit, ik weet niet hoe dat moet in chrome (wel in ie maar das gwn KUT)
 
- Ariën  -
Beheerder

- Ariën -

20/04/2011 20:24:46
Quote Anchor link
F5

Een wit beeld in phpMyAdmin is niet tof. Als het in geen enkele browser werkt, meot je eens contact opnemen met je hosting, die heeft zijn zaakjes eventjes niet best voor elkaar dan.
 
Huppelpup php

huppelpup php

20/04/2011 20:26:37
Quote Anchor link
- Aar - op 20/04/2011 20:24:46:
F5

Een wit beeld in phpMyAdmin is niet tof. Als het in geen enkele browser werkt, meot je eens contact opnemen met je hosting, die heeft zijn zaakjes eventjes niet best voor elkaar dan.

Ok ik ga wel even een berichtje sturen ik hou jullie op de hoogte



Toevoeging op 20/04/2011 20:32:41:

Huppelpup php op 20/04/2011 20:26:37:
- Aar - op 20/04/2011 20:24:46:
F5

Een wit beeld in phpMyAdmin is niet tof. Als het in geen enkele browser werkt, meot je eens contact opnemen met je hosting, die heeft zijn zaakjes eventjes niet best voor elkaar dan.

Ok ik ga wel even een berichtje sturen ik hou jullie op de hoogte



eehm wat is het email adres van x10hosting (kan het niet vinden)
 
Gerhard l

gerhard l

20/04/2011 20:32:52
Quote Anchor link
openen in internet explorer..
 
Huppelpup php

huppelpup php

20/04/2011 20:44:56
Quote Anchor link
Gerhard l op 20/04/2011 20:32:52:
openen in internet explorer..


in IE kan ik niet inloggen en met chrome krijg ik wit beeld
 
Gerhard l

gerhard l

20/04/2011 20:45:53
Quote Anchor link
hoezo kan je neit inloggen? Op mijn host krijg ik ook altijd wit beeld maar met IE werkt het gewoon
 
Huppelpup php

huppelpup php

20/04/2011 20:47:38
Quote Anchor link
Gerhard l op 20/04/2011 20:45:53:
hoezo kan je neit inloggen? Op mijn host krijg ik ook altijd wit beeld maar met IE werkt het gewoon


op ie krijg ik dit

#1045 Kan niet inloggen op de MySQL-server
 

Pagina: 1 2 volgende »



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.