Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/233310-how-to-make-gamesphpid/
Share on other sites

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?

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.

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.

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.

 

 

 

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>';
       
}
?>

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='

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" />';
?>

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.

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.

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.

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>";

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.

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  :shrug:.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.