netroxy Posted April 11, 2011 Share Posted April 11, 2011 Hey guys. I am building a games website, and I am using ID (example: games.php?id_) to view games with their Title, SWF file to play, and their Image Icon. I am basically fetching information per game using ID that is typed in the URL after my website address containing the '?id_' or '?id='. Can somebody tell me whats wrong with the code I have bellow, because it's not working. I always get parse error (T_STRING) at line 9. This code is inside my games.php page. It doesn't seem to work. ================================ <?php $conn = mysql_connect("host", "username", "password"); mysql_select_db("games"); $game_id = $_GET['id']; $sql = "SELECT * FROM games WHERE id='$game_id' LIMIT 1"; $result = mysql_query($sql, $conn) or die(mysql_error()); $number_of_results = mysql_num_rows($result); while ($result_array = mysql_fetch_array($result, MYSQL_ASSOC)) { $id = $result_array['fldID']; $title = $result_array['fldTitle']; $graphic = $result_array['fldIconSmall']; // Example: game1234.png $swf = $result_array['fldSwfSrc']; // Example: game1234.swf $graphic_file_location = 'http://www.blabla.com/games/images/' . $graphic; $swf_file_location = 'http://www.blabla.com/games/' .$swf; echo '<a href="http://www.blabla.com/games.php?id=' . $id . '"></a>'; echo '<h1>' . $title . '</h1>'; echo '<img src="' . $graphic_file_location . '" width="50" height="50" border="0" />'; echo '<object width="550" height="400">'; echo '<param name="movie" value="' . $swf_file_location . '">'; echo '<embed src="' . $swf_file_location . '" width="550" height="400">'; echo '</embed>'; echo '</object>'; } ?> ================================ Any help would be appreciated since so far this script has not executed at all. I keep getting an error when executing this entire script. I can't find any errors in it either..but it just doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/ Share on other sites More sharing options...
dcro2 Posted April 11, 2011 Share Posted April 11, 2011 Either something's wrong with your php configuration or that's not all the code being executed. That's absolutely positively ALL the code in your php file? Can any other php file run normally? Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199851 Share on other sites More sharing options...
netroxy Posted April 11, 2011 Author Share Posted April 11, 2011 Other PHP files can run normally like my counter script. This one however, I can't seem to execute it properly. I placed this code above in my games.php. As you can see, the code fetches ID number from my link in the address bar, which then finds the rest of the information in the mysql table due to the ID. My problem is, I just get a STRING error in line 9, which I have no idea why. You think this is all the code I need to fetch ID and retrieve its information from a table? Or is there more scripting that I have to put into it? Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199852 Share on other sites More sharing options...
netroxy Posted April 11, 2011 Author Share Posted April 11, 2011 You can see that I am trying to retrieve the Title of the game, the SWF file to execute the game and the Image file of the game connecting through ID's that are typed in the link of my website right after 'games.php' including the '?id_'. Example of a link would be 'www.blabla.com/games.php?id_12345. If anybody has another way of fetching information through ID in links, I would love to see your codes as it might benefit my game site. Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199855 Share on other sites More sharing options...
dcro2 Posted April 11, 2011 Share Posted April 11, 2011 The correct format should be this: http://www.blabla.com/games.php?id=12345 I don't see an error with your code, although you shouldn't need a loop if you know you'll get only one row back. Can you put this above everything and see if you get any other errors? Just copy and paste here the errors exactly how you get them. error_reporting(E_ALL); ini_set("display_errors", 1); Also, check your web server error log if you can for any errors that don't get displayed in your browser. Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199857 Share on other sites More sharing options...
netroxy Posted April 11, 2011 Author Share Posted April 11, 2011 I've placed the error reporting script you placed right above the script. I can copy and paste the code back again but it shows no errors. Completely Blank. Do you have another alternative to the code I have written above? Maybe a different example that might work? I can give an example of a page that might preview information from an ID's row. So a user types or clicks on 'www.blabla.com/games.php?id=12345' After, accessing that link, the user views the information in games.php: <html>fldGameName</html> ======================== | | | | | | |<html>Flash Game executed| | (fldSwfFile)</html> | | | | | | | ======================= <html>fldImageIcon</html> So you can see, the Title is above, Flash game is in the middle, and the Image Icon is below the flash game. Do you have another approach excluding my script? Firstly connecting to database, GETting ID from link, retrieving ID and then displaying information from ID's row and displaying it in games.php. Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199860 Share on other sites More sharing options...
QuickOldCar Posted April 11, 2011 Share Posted April 11, 2011 Since your GET is game_id and not id, shouldn't it be this? http://www.blabla.com/games.php?game_id=12345 Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199867 Share on other sites More sharing options...
QuickOldCar Posted April 11, 2011 Share Posted April 11, 2011 This work? <?php $conn = mysql_connect("host", "username", "password"); mysql_select_db("games"); $id = $_GET['id']; if (!isset($_GET['id']) || $id == ''){ //echo "No ID inserted"; $id = 12345;//some default value } $sql = "SELECT * FROM games WHERE id='$id' LIMIT 1"; $result = mysql_query($sql, $conn) or die(mysql_error()); $number_of_results = mysql_num_rows($result); while ($result_array = mysql_fetch_array($result, MYSQL_ASSOC)) { $game_id = $result_array['fldID']; $title = $result_array['fldTitle']; $graphic = $result_array['fldIconSmall']; // Example: game1234.png $swf = $result_array['fldSwfSrc']; // Example: game1234.swf $graphic_file_location = 'http://www.blabla.com/games/images/' . $graphic; $swf_file_location = 'http://www.blabla.com/games/' .$swf; echo "<a href='http://www.blabla.com/games.php?id=$game_id'>$title</a>"; echo '<h1>' . $title . '</h1>'; echo '<img src="' . $graphic_file_location . '" width="50" height="50" border="0" />'; echo '<object width="550" height="400">'; echo '<param name="movie" value="' . $swf_file_location . '">'; echo '<embed src="' . $swf_file_location . '" width="550" height="400">'; echo '</embed>'; echo '</object>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199869 Share on other sites More sharing options...
netroxy Posted April 11, 2011 Author Share Posted April 11, 2011 Yes I have tried that. It doesn't work either. I apologies because I am fairly new to PHP. I do need some experts help on this. Do you have another approach to the code I have written above? How would you fetch an ID's information from a row, such as Title, Displaying SWF file, and displaying a GIF/Jpg IMAGE from a mysql table. If you'd like to see an example of what I mean, you can visit www.game68.com and surf that game website. Click on a game and you can see how each link posted on the website directly retrieves information of a particular ID from the link that includes the 'games.php?id=' Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199870 Share on other sites More sharing options...
dcro2 Posted April 11, 2011 Share Posted April 11, 2011 Another version for you to try. Make sure to specify an id that exists in your table. <?php error_reporting(E_ALL); ini_set('display_errors', 1); if(empty($_GET['id'])) { die("No game id specified."); } $conn = mysql_connect("localhost", "username", "password") or die("Error connecting to database: ".mysql_error()); mysql_select_db("games", $conn) or die("Could not select database: ".mysql_error()); $sql = "SELECT * FROM games WHERE id='".$_GET['id']."' LIMIT 1"; $result = mysql_query($sql, $conn) or die("MySQL error in '".$sql."': ".mysql_error()); $numrows = mysql_num_rows($result); if($numrows == 0) die("Could not find the game for this id."); $result_array = mysql_fetch_array($result); $id = $result_array['fldID']; $title = $result_array['fldTitle']; $graphic = $result_array['fldIconSmall']; $swf = $result_array['fldSwfSrc']; $graphic_file_location = 'http://www.blabla.com/games/images/' . $graphic; $swf_file_location = 'http://www.blabla.com/games/' . $swf; echo '<h1>' . $title . '</h1>'; echo '<object width="550" height="400">'; echo '<param name="movie" value="' . $swf_file_location . '">'; echo '<embed src="' . $swf_file_location . '" width="550" height="400">'; echo '</embed>'; echo '</object>'; echo '<img src="' . $graphic_file_location . '" width="50" height="50" border="0" />'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199871 Share on other sites More sharing options...
QuickOldCar Posted April 11, 2011 Share Posted April 11, 2011 http://www.game68.com/ is a related search site Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199872 Share on other sites More sharing options...
netroxy Posted April 11, 2011 Author Share Posted April 11, 2011 I apologies. Heres the actual link. http://www.games68.com/ I tried the script you have written, but I have no way to fetch ID through link. Unless I am the one being confused. This game website should probably give you an understanding of what I mean if you look closely at the ID's in the links for each of the games posted. All game links end with id?=, and then the ID number. So I assume each ID per game fetches the rows of information such as Title, SWF file executed, and Image Icon and all detailed information per game is displayed in games.php. Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199874 Share on other sites More sharing options...
dcro2 Posted April 11, 2011 Share Posted April 11, 2011 Yeah, we all get the model you're talking about. Don't you have any rows in your games database already? Just use the id of one of those to test the script. For example, if you have a row in your database with the id 123, and your site is hosted on your computer, you would use something like this link: http://localhost/games.php?id=123 You don't have to have the link already in another page, just type it in directly in your browser. Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199875 Share on other sites More sharing options...
netroxy Posted April 11, 2011 Author Share Posted April 11, 2011 I have 5 records with ID's. I did place an id in 'www.blabla.com/games.php?id=12345' and it didn't work. I see you removed echo '<a href="http://www.blabla.com/games.php?id=' . $id . '"></a>';. Don't I need this so any ID written in the link works? Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199879 Share on other sites More sharing options...
dcro2 Posted April 11, 2011 Share Posted April 11, 2011 If you kept the link that I removed, you'd have a link to the exact same page you're already on, so I don't get the point. I'm not sure if you understand how all this works. This page is presumably linked to from another page which lists more than one game. When you reach this page, you want to see a single game. Putting a link to the same page would make no sense. Is your site hosted somewhere or is it on your computer at the moment? If it's on a domain we can visit, could you please tell us what that is so we can guide you better? I'm beginning to think it's not a problem with the code, but with the way you access it. Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199884 Share on other sites More sharing options...
QuickOldCar Posted April 11, 2011 Share Posted April 11, 2011 Just for the record I have a games site with wordpress that I import games through mochiads. http://dynainternet.com/games/ Over 30,000 games there. Yeah he probably forgot the href link, you could also do the image itself in the href link. echo "<a href='$swf_file_location' target='_blank'><img src='$graphic_file_location' border='0'></a>"; Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199885 Share on other sites More sharing options...
netroxy Posted April 11, 2011 Author Share Posted April 11, 2011 - Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199893 Share on other sites More sharing options...
netroxy Posted April 11, 2011 Author Share Posted April 11, 2011 - Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199894 Share on other sites More sharing options...
netroxy Posted April 11, 2011 Author Share Posted April 11, 2011 http://www.netroxy.com/index.htm As you can see, Action, Shooter and Adventure section above the site have the links similar to what we are discussing. They all include the games.php?id= in their links. They link to games.php page which I uploaded into the web host alongside the index.htm page. Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199895 Share on other sites More sharing options...
dcro2 Posted April 11, 2011 Share Posted April 11, 2011 Thanks for the link. Well, I know you must be frustrated, but I can't imagine why a page with the exact code I gave you would turn up that error. Usually this error turns up when there's an unescaped single/double quote or a missing dot or something. I even ran the code on my computer and I get nothing besides mysql connection errors. Maybe there's something going on with the way you uploaded the php file. It's possible your editor might have put different kind of quotes or.. well, I really don't know . If you have ssh access, which you should with GoDaddy, try to check if the code matches what you uploaded with cat, etc. Otherwise, maybe someone else will be able to figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199901 Share on other sites More sharing options...
netroxy Posted April 11, 2011 Author Share Posted April 11, 2011 Thanks for your help. I'll look in to the codes you've given me and I'll see what I can resolve with it. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/#findComment-1199906 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.