User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 392,054 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,290 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 2063 | Replies: 4
Reply
Join Date: Feb 2005
Location: UK
Posts: 44
Reputation: kevin_smithers is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
kevin_smithers's Avatar
kevin_smithers kevin_smithers is offline Offline
Light Poster

Connection problem

  #1  
Feb 20th, 2005
Hi,
I have a small problem I have a flash game SWF file not the fla and it sends and recieves values from a PHP file send - update and recieve is INIT

Great except the person who gave me the SWF and PHP file did not tell me how to set up the database If I was to post the code could someone tell me the table layout to wright with PHP My Admin?

I know its only a small database we are talking 4 or 5 objects in 1 table but I just cant get my head around the code not knowing PHP

Cheers

Kev
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2003
Location: Toronto, Canada
Posts: 354
Reputation: Gary King will become famous soon enough Gary King will become famous soon enough 
Rep Power: 6
Solved Threads: 5
Colleague
Gary King's Avatar
Gary King Gary King is offline Offline
PHP/vBulletin Guru

Re: Connection problem

  #2  
Feb 21st, 2005
Sure, post the code. It'd help.
Reply With Quote  
Join Date: Feb 2005
Location: UK
Posts: 44
Reputation: kevin_smithers is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
kevin_smithers's Avatar
kevin_smithers kevin_smithers is offline Offline
Light Poster

Re: Connection problem

  #3  
Feb 21st, 2005
[PHP]<?

if ($command=="init"){
$link = @mysql_connect("localhost", "username", "password");

if (!$link){
print "&message=Error connecting to database";
exit;
}

if (!@mysql_select_db("kevinsmi_game")){
print "&message=Couldn't select database";
exit;
}

$players = "";
$scores = "";
$distances = "";
$victims = "";
$innerquery = "SELECT * FROM game ORDER BY scores DESC";
$innerresult = @mysql_query($innerquery);
$numPlayers=mysql_num_rows($innerresult);
for($loop=0;$loop<$numPlayers; $loop++) {
$newPlayer = mysql_result($innerresult,$loop,"players");
$newScore = mysql_result($innerresult,$loop,"scores");
$newDistance = mysql_result($innerresult,$loop,"distances");
$newVictim = mysql_result($innerresult,$loop,"victims");
$players = "$players<br>$newPlayer";
$scores = "$scores<br>$newScore";
$distances = "$distances<br>$newDistance";
$victims = "$victims<br>$newVictim";
}
printf("&players=%s", $players);
printf("&scores=%s", $scores);
printf("&distances=%s", $distances);
printf("&victims=%s", $victims);

mysql_close($link);


}


if ($command=="update"){
$link = @mysql_connect("localhost", "username", "password");

if (!$link){
print "&message=Error connecting to database";
exit;
}

if (!@mysql_select_db("game")){
print "&message=Couldn't select database";
exit;
}

$players = "";
$scores = "";
$query = "SELECT scores FROM game where players = '$name'";
$result = @mysql_query($query);
if(@mysql_num_rows($result)>0){
$oldScore = mysql_result($result,"scores");
if($score>$oldScore){
$query = "UPDATE game SET scores = '$score' where players = '$name'";
$result = @mysql_query($query);
}
}

else {
$query ="INSERT INTO game (players, scores, distances, victims) VALUES ('$name', '$score', '$distance', '$victim')";
$result = @mysql_query($query);
}

$innerquery = "SELECT * FROM game ORDER BY scores DESC";
$innerresult = @mysql_query($innerquery);
$numPlayers=mysql_num_rows($innerresult);
for($loop=0;$loop<$numPlayers; $loop++) {
$newPlayer = mysql_result($innerresult,$loop,"players");
$newScore = mysql_result($innerresult,$loop,"scores");
$newDistance = mysql_result($innerresult,$loop,"distances");
$newVictim = mysql_result($innerresult,$loop,"victims");
$players = "$players<br>$newPlayer";
$scores = "$scores<br>$newScore";
$distances = "$distances<br>$newDistance";
$victims = "$victims<br>$newVictim";
}
printf("&players=%s", $players);
printf("&scores=%s", $scores);
printf("&distances=%s", $distances);
printf("&victims=%s", $victims);

mysql_close($link);
}
?>[/PHP]
Reply With Quote  
Join Date: Feb 2005
Posts: 354
Reputation: DanceInstructor is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 12
DanceInstructor's Avatar
DanceInstructor DanceInstructor is offline Offline
Posting Whiz

Re: Connection problem

  #4  
Feb 27th, 2005
So... you realize you are trying to use 2 databases??

for command == "init" you have: mysql_select_db("kevinsmi_game")

for command == "update" you have mysql_select_db("game")

As far as the table:
db name: kevinsmi_game
table: game
field1: players
field2: scores
field3: distances
field4: victims
Clear Mind Hosting and Web Design

If I've helped you please consider adding to my reputation.
Reply With Quote  
Join Date: Feb 2005
Location: UK
Posts: 44
Reputation: kevin_smithers is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
kevin_smithers's Avatar
kevin_smithers kevin_smithers is offline Offline
Light Poster

Re: Connection problem

  #5  
Feb 27th, 2005
Cheers for that didn't notice I hadn't changed the second connection values :-)

I still can't get the thing to work though!! It is bugging me, I have the database set up as you have layed out above and that is how I have had it done from the start, but I just can't get it to read or write ot the database I have set up a simple table on a blank page and connected to the database through a simple table connection in dreamweaver and that works OK!!!!!!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 11:38 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC