Jump to content

Mysql Game Selection


sweinkauf13

Recommended Posts

Ok, so i'm working on a project which has an "arcade". Now it uses a mysql database called "arcade" and a table called "games" that holds all the information on the games. Now each game link points to one document "playgame.phtml". shown below:

<?session_start();if(($_SESSION[username] == "") ||($_SESSION[password] == "")){header("location: login.phtml");exit;}?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head><title>Family Connection</title><link rel=stylesheet type="text/css" href="style.css"></head><body><div class="login_outline"><br><br><p><center><img src="header_image.gif" alt="Header Image" width="625"></center></p>	<div class="login_body"><p>Welcome, <? echo "$_SESSION[real_name]"; ?> [<a href="logout.php">Log Out</a>]</p>		<div class="menu"><div class="button_1"><a href="home.phtml" class="button"><p>Home<p></a></div><div class="button_2"><center><a href="add_date_step_one.php" class="button"><p>Add A Date To The Calandar</p></a></center></div><div class="button_3"><center><a href="fms/index.php" class="button"><p>Family Mail Service</p></a></center></div><div class="button_4"><center><p><a href="feedback.html" class="button">Feedback</a></p></center></div><div class="button_5"><center><p><a href="quick_links.phtml" class="button">Quick Links</a></p></center></div><div class="button_6"><center><p><a href="arcade.phtml" class="button">Arcade</a></p></center></div><?If($_SESSION[username] == "admin"){$button = "<div class=\"button_7\"><center><p><a href=\"admin_mode/admin_index.phtml\" class=\"button\">Admin Mode</a></p></center></div>";#echo("$button");}else{$button = "<div class=\"button_7\"><center><p><a href=\"picks.phtml\" class=\"button\">Top Picks</a></p></center></div>";echo("$button");}?><br><br><br><p><hr size="2" color="black" class="divide_line"></p><p><?$g ="$_POST[game]";$connection = @mysql_connect('localhost','username','password') or die(mysql_error());$database = "arcade";$tb = "games";#$db = @mysql_select_db("$database","$connection") or die(mysql_error());$sql = "select * from $tb where game_id==$g;";$result = @mysql_query("$sql","$connection") or die(mysql_error());#$row = @mysql_fetch_array($result) or die(mysql_error());$game = $row['gamecode'];echo "$game";?></p>		</div></div></body></html>

Now this document recieves the "id" of the game the user wants from the button on the previous page.($_POST[game]). So this script is supose to go and match the id number that it got to the corisponing one in the mysql table and then get the information out of the "gamecode" column. Which has something like this in it:

<embed src="http://www.addictinggames.com/D78AQSAKQLQWI9/5173.swf" type="application/x-shockwave-flash" width="720" height="600"></embed><br><a href="http://www.addictinggames.com" target="_blank" title="Play Games">Play Games at AddictingGames</a>

Then echo this code out to the page which should produce the game that the user wanted. Now when i used the code first shown, it parsed and showed a page. but no game! i checked the source for the page it was showing and it was blank after the black line (<hr>). So it's like the code didn't parse. So then i went and changed the code to make an error, and then refreshed the page and it showed an error message, so i know the script is being parsed. But then why am i seeing no game? Please help me. Did i do something wrong? I'm relitivly new to useing php and mysql together like this. If there is anything more you need from me, please let me know.thank you in advance,youngwebmaster

Link to comment
Share on other sites

Ok. Maybe people aren't responding because of the size of the document i showed. Here is just the part of the document that i am having problems with:

<p><?$g ="$_POST[game]";$connection = @mysql_connect('localhost','username','password') or die(mysql_error());$database = "arcade";$tb = "games";#$db = @mysql_select_db("$database","$connection") or die(mysql_error());$sql = "select * from $tb where game_id==$g;";$result = @mysql_query("$sql","$connection") or die(mysql_error());#$row = @mysql_fetch_array($result) or die(mysql_error());$game = $row['gamecode'];echo "$game";?></p>

I hope this helpes. I really need help on this as soon as possible because i was hoping to give this project as a gift to my family on christmas. 2 days away.thank you,youngwebmaster

Link to comment
Share on other sites

i think the problem is that u use == instead of =$sql = "select * from $tb where game_id = $g;";and assuming that game_id is an integer, its safer to use $g =(int)$_POST['game']; instead of $g ="$_POST[game]";

Link to comment
Share on other sites

  • 2 weeks later...

ok, so i edited the script for what you said. Here's what i've got.

<p><?$g =(int)$_POST['game'];$connection = @mysql_connect('localhost','username','password') or die(mysql_error());$database = "arcade";$tb = "games";#$db = @mysql_select_db("$database","$connection") or die(mysql_error());$sql = "select * from $tb where game_id = $g;";$result = @mysql_query("$sql","$connection") or die(mysql_error());#$row = @mysql_fetch_array($result) or die(mysql_error());$game = $row['gamecode'];echo "$game";?></p>

but i still get the same result. Nothing. Is there anything else? I'm sure i'm overlooking something but i'm not sure what.thanks,youngwebmaster

Link to comment
Share on other sites

problem might be that u use "$connection" instead of just $connection (remove the quotes)?with the "$sql" and "$database" it doesnt matter because these are strings anyway, but $connection is a resource

Link to comment
Share on other sites

thank you. It is now working. I thank everyone who helped me solve this problem.So that people can see how this was resolved i'm posting my code below. I hope this can help someone else as well.

<?$g =(int)$_POST['game'];$connection = @mysql_connect('localhost','username','password') or die(mysql_error());$database = "arcade";$tb = "games";#$db = @mysql_select_db("$database",$connection) or die(mysql_error());$sql = "select * from $tb where game_id = $g";$result = @mysql_query("$sql",$connection) or die(mysql_error());#$row = @mysql_fetch_array($result) or die(mysql_error());$game = $row['gamecode'];echo "$game";?>

Thanks again,youngwebmaster

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...