/    Sign up×
Community /Pin to ProfileBookmark

errors, errors everywhere.. but not a drop to drink ^_^;

I have been trying to do some simple PHP to help with a Game Data Base on my website. i can’t use MySQL because the server does not support it BUT i am doing well with text files to store the info..

now the program is i keep getting errors.. really, i don’t know much about PHP so am a bit stuck. The Current error is ‘unexpected T_VARIABLE’.. All the errors seam to appear within the first few lines, which are the following..

[code=php]<?php

// Script pretty much created by Manic Man with help ^_^
// Declare Variable
global $GameTitle; //Name of the Game
global $GamePic; //Shorten Name used for Pictures etc..
global $Developer; //Developer Name
global $ReleaseJP; //Japanese Release Date
global $ReleaseUK; //English Release Date
global $ReleaseUS; //Amercian Release Date
global $Style; //Game Style
global $ActInfo; //Text about Level size
global $LevTot; //Total Number of Levels
global $LevNum; //Place to store Current Level Number
global $Levtitle; //Title of Current Level
global $userPage; //Stores the Page Name to be used in file getting
global $TextArray; //Temp array
global $N; //stores which number off the array is being added to
$N = 0;
?>

<?php
$userPage = $_GET[“page”];
$file = file($userPage & ‘.txt’);
foreach($file as $val)
{
$TextArray[$N] = ‘$val’;
$N = $N + 1;
}
?>

<? php
$GameTitle = $TextArray[0];
$GamePic = $TextArray[1];
$Developer = $TextArray[2];
$ReleaseJP = $TextArray[3];
$ReleaseUK = $TextArray[4];
$ReleaseUS = $TextArray[5];
$Style = $TextArray[6];
$ActInfo = $TextArray[7];
$LevTot = $TextArray[8];
$LevNum = $TextArray[9];
$Levtitle = $TextArray[10];
?>[/code]

I have so many <?php ?> because i find it easyer to have it in small bits so i can check it easyer.. what do you lot think?

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 30.2005 — In your last block of code, you have a space between the "<?" and the "php" which is causing the parse error.
Copy linkTweet thisAlerts:
@Manic_ManauthorMar 31.2005 — thanks! now the problem i have appears to be on images...

the error is on a line when i have a varible storing the name for the file.. here is the line...

[code=php]
<img src="TitleScreen/'$GamePic'.jpg" ALT="'$GameTitle' title Screen"><br>
[/code]


that appears to be the only other error.. then it should be fine..
Copy linkTweet thisAlerts:
@solomonMar 31.2005 — it's a little hard to say because it's out of context, but it looks like you're mixing html and php... try something like this:

[code=php]<img src="TitleScreen/<?php echo $GamePic; ?>.jpg" ALT="<?php echo $GameTitle; ?> title Screen"><br> [/code]

or
[code=php]
<?php
echo "<img src="TitleScreen/".$GamePic.".jpg" ALT="".$GameTitle." title Screen"><br>n"
?>[/code]


which amounts to the same thing.

HTH
Copy linkTweet thisAlerts:
@Manic_ManauthorMar 31.2005 — erm.. i appear to have fixed that for now BUT all of my Text Input is wrong..

i need it to take the name in the path (Game.PHP?Page=Sonic1MD) take the Sonic1MD and add a .txt to it so it has Sonic1MD.txt and then take each line of that file and put it into a different variblie.. it does not seam to be working.. this is the code i have..

[code=php]
<?php
$userPage = $_GET["page"];
$file = file($userPage & '.txt');
foreach($file as $val)
{
$TextArray[$N] = '$val';
$N = $N + 1;
}
?>
[/code]
Copy linkTweet thisAlerts:
@MarkLMar 31.2005 — erm.. i appear to have fixed that for now BUT all of my Text Input is wrong..

i need it to take the name in the path (Game.PHP?Page=Sonic1MD) take the Sonic1MD and add a .txt to it so it has Sonic1MD.txt and then take each line of that file and put it into a different variblie.. it does not seam to be working.. this is the code i have..

[code=php]
<?php
$userPage = $_GET["page"];
$file = file($userPage & '.txt');
foreach($file as $val)
{
$TextArray[$N] = '$val';
$N = $N + 1;
}
?>
[/code]
[/QUOTE]


PHP uses . or .= instead of & to concatenate strings, you also may want to consider assembling the filename before making the file() function call. Also, being an old school programmer I like to initialize any variables that need to hold a certain value, such as the $N variable you are using in this script. I would change the script to this:

[code=php]
<?php
$N = 0;
$userPage = $_GET["page"];
$userPage .= '.txt';
$file = file($userPage);
foreach($file as $val)
{
$TextArray[$N] = '$val';
$N = $N + 1;
}
?>
[/code]
Copy linkTweet thisAlerts:
@Manic_ManauthorMar 31.2005 — great... but now it appears that the "$TextArray[$N] = '$val';" is not working right.. ALL of the strings in the Array turn out as $val. So... that creates another problem ^_^;
Copy linkTweet thisAlerts:
@MarkLMar 31.2005 — great... but now it appears that the "$TextArray[$N] = '$val';" is not working right.. ALL of the strings in the Array turn out as $val. So... that creates another problem ^_^;[/QUOTE]

Just remove the single quotes from around $val and you should be set.
Copy linkTweet thisAlerts:
@Manic_ManauthorMar 31.2005 — You are a nice bloke! ^_^

1 problem left which i can see.. the images don't seam to work.. what that solomon bloke told me does not seam to work.

[code=php]<img src="TitleScreen/".$GamePic.".jpg" ALT="".$GameTitle." title Screen">[/code]

so.. what do you think?
Copy linkTweet thisAlerts:
@MarkLMar 31.2005 — You are a nice bloke! ^_^

1 problem left which i can see.. the images don't seam to work.. what that solomon bloke told me does not seam to work.

[code=php]<img src="TitleScreen/".$GamePic.".jpg" ALT="".$GameTitle." title Screen">[/code]

so.. what do you think?[/QUOTE]


Try this:

[code=php]
echo '<img src="TitleScreen/'.$GamePic.'.jpg" ALT="'.$GameTitle.' title Screen">';
[/code]
Copy linkTweet thisAlerts:
@Manic_ManauthorMar 31.2005 — Whay!

I told you, you were a nice bloke ^_^ it works fine..

the rest of the thing i need to work on is pretty easy i think. If i need any more help i will ask ^_^!
Copy linkTweet thisAlerts:
@solomonMar 31.2005 — You are a nice bloke! ^_^

1 problem left which i can see.. the images don't seam to work.. what that solomon bloke told me does not seam to work.

[code=php]<img src="TitleScreen/".$GamePic.".jpg" ALT="".$GameTitle." title Screen">[/code]

so.. what do you think?[/QUOTE]

I just tested the lines of code I suggested and they both work fine. It looks like you didn't actually apply either of my suggestions :p

erm.. i appear to have fixed that for now BUT...[/QUOTE]
... the case for the defense rests, m'lud ?
×

Success!

Help @Manic_Man spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...