Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

A Parse Error Problem


20 replies to this topic

#1 shadowdemon

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 209 posts

Posted 01 April 2006 - 01:22 AM

<?php include ("header.php"); 
echo "<br>Welcome to the construction site. Randomly we will update this place with stuff you can do. Currently we are offering you to make a building where you can make trade gold for ap or platinum for ap. The cost of this project is all 10k silver wood.</br>"; 

if ($stat[construction] <= 1) 
{ 
print 'Would you like to start the building';
echo "<a href="construction.php?action=construct">construct</a> ";
)
if ($action == construct) 
{ 
print "you have started construction $stat[user]...<br><br>"; 
mysql_query("Update players Set construction=yes where id=stat[id] "); 
//a verification should be made if the player has the right amount of silver wood before making that query 
//else you'll end up with - numbers.. 
mysql_query("Update players Set silver wood = $stat[silverwood]-10000 where stat[id] "); 
mysql_query("Update players Set construction = stat[construction]+1 where stat[id] "); 
print "</table><br>"; 
print "Or you can always... <a href=city.php>go back</a>."; 
} 
} 
if ($stat[constructed] => 2) 
{ 
$prices = mysql_query("select * from market"); 
$pa = mysql_fetch_array($prices); 
$plat_price = $pa[ap]; 
if ($action != buy) { 
print "Ap isn't always a stable-priced commodity... right now its $plat_price credits an ap. How much you want?"; 
print "<form method=post action=construction.php?action=buy>"; 
print "I want <input type=text name=plat> ap. <input type=submit value=Buy>"; 
print "</form>"; 
} else { 
$plat = str_replace("--","", $plat); 
$cost = ($plat * $plat_price); 
if ($cost > $stat[credits] || $plat <= 0) { 
print "You cant afford that! (<a href=pshop.php>back</a>)"; 
} else { 
mysql_query("update players set credits=credits-$cost where id=$stat[id]"); 
mysql_query("update players set ap=ap+$plat where id=$stat[id]"); 
print "You got <b>$plat</b> ap for <b>$cost</b> credits."; 
} 
} 

?> 

<? include ("footer.php"); ?> 

and the error is

Quote

Parse error: parse error, expecting `','' or `';'' in /home/www/dancha42.madpage.com/construction.php on line 7

if thes dont show up as quotes could a mod fix it please.



this is for a text based game so it may seem different. But it shouldnt matter since the parse error shouldnt interfer with it.

Edited by jlhaslip, 01 April 2006 - 06:28 PM.


#2 jlhaslip

    Insert Custom Title Here

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,037 posts
  • Gender:Male
  • Location:Linux, DOS and Windows…the good, the bad and the ugly
  • Interests:http://jim.haslip.googlepages.com/home
  • myCENT:53.48
  • Spam Patrol

Posted 01 April 2006 - 01:26 AM

What you have currently:
if ($stat[construction] <= 1)
{
print 'Would you like to start the building';
echo "<a href="construction.php?action=construct">construct</a> ";
)
And what you might need to change is the last end parenthesis to a right-curly brace. Like this:
if ($stat[construction] <= 1)
{
print 'Would you like to start the building';
echo "<a href="construction.php?action=construct">construct</a> ";
}


#3 Tyssen

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,161 posts
  • Location:Brisbane, QLD

Posted 01 April 2006 - 01:27 AM

This line:

echo "<a href="construction.php?action=construct">construct</a>";
should be:
echo '<a href="construction.php?action=construct">construct</a>';
or:
echo "<a href=\"construction.php?action=construct\">construct</a>";
PHP is going to execute anything within the " " or ' ' so in your case, it gets to the " after the href and then stops.

#4 shadowdemon

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 209 posts

Posted 01 April 2006 - 02:31 PM

now i get this
Parse error: parse error in /home/www/dancha42.madpage.com/construction.php on line 20

i hate parse errors. im gonna try and figure it out myself but if you what to fix your suggestions are welcomed

#5 jlhaslip

    Insert Custom Title Here

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,037 posts
  • Gender:Male
  • Location:Linux, DOS and Windows…the good, the bad and the ugly
  • Interests:http://jim.haslip.googlepages.com/home
  • myCENT:53.48
  • Spam Patrol

Posted 01 April 2006 - 03:43 PM

you have :

if ($stat[constructed] => 2) 

try:

if ($stat[constructed] >= 2) 


#6 shadowdemon

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 209 posts

Posted 01 April 2006 - 04:19 PM

View Postjlhaslip, on Apr 1 2006, 10:43 AM, said:

you have :

if ($stat[constructed] => 2) 

try:

if ($stat[constructed] >= 2) 

doesnt fix the parse error but that is becuase it isnt on line 20 so you might have fixed a later parse error but i still need some help with the line 20 one

#7 jlhaslip

    Insert Custom Title Here

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,037 posts
  • Gender:Male
  • Location:Linux, DOS and Windows…the good, the bad and the ugly
  • Interests:http://jim.haslip.googlepages.com/home
  • myCENT:53.48
  • Spam Patrol

Posted 01 April 2006 - 05:17 PM

It might not like the whitespace and carriage return here:
if ($action == construct)
{
print "you have 
Try this for the If statements:
if ($action == construct) {
print "you have 


#8 truefusion

    Coincidence is non-sequitur, therefore everything has a reason for its existence (except if they are eternal).

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 3,216 posts
  • Gender:Male
  • Location:No, not there. Not there either. Yes, you'll never figure it out.
  • Interests:God, Christianity.
  • myCENT:84.24

Posted 01 April 2006 - 05:28 PM

On line 2, the <br> tag doesnt work like that.

And for this:

Quote

if ($stat[construction] <= 1)
{
print 'Would you like to start the building';
echo "<a href=\"construction.php?action=construct\">construct</a> ";
)
I think the thing in bold is the problem. May want to change it to: }

Edited by truefusion, 01 April 2006 - 05:29 PM.


#9 shadowdemon

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 209 posts

Posted 01 April 2006 - 06:16 PM

View Posttruefusion, on Apr 1 2006, 12:28 PM, said:

On line 2, the <br> tag doesnt work like that.

And for this:

I think the thing in bold is the problem. May want to change it to: }
fixed that earlier


View Postjlhaslip, on Apr 1 2006, 12:17 PM, said:

It might not like the whitespace and carriage return here:
if ($action == construct)
{
print "you have 
Try this for the If statements:
if ($action == construct) {
print "you have 


ill try this out ty

i thought spaces dont matter in php
yeah i was right spaces dont matter cause i still get

Parse error: parse error in /home/www/dancha42.madpage.com/construction.php on line 19 (was 20 but then the space made it drop down one)


the error is around here

mysql_query("Update players Set silver wood = $stat[silverwood]-10000 where stat[id] ");
mysql_query("Update players Set construction = stat[construction]+1 where stat[id] ");
print "</table><br>";
print "Or you can always... <a href=city.php>go back</a>.";
}
}
if ($stat[constructed] >= 2)

but i dont see what is wrong (match this up with the code but it is around this area more specifically print "</table<br>":angry:

Edited by shadowdemon, 01 April 2006 - 06:22 PM.


#10 jlhaslip

    Insert Custom Title Here

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,037 posts
  • Gender:Male
  • Location:Linux, DOS and Windows…the good, the bad and the ugly
  • Interests:http://jim.haslip.googlepages.com/home
  • myCENT:53.48
  • Spam Patrol

Posted 01 April 2006 - 06:25 PM

View Postshadowdemon, on Apr 1 2006, 11:16 AM, said:

fixed that earlier
ill try this out ty

i thought spaces dont matter in php
yeah i was right spaces dont matter cause i still get

Parse error: parse error in /home/www/dancha42.madpage.com/construction.php on line 19 (was 20 but then the space made it drop down one)
Sometimes an editor will plant invisible things in there. I happen to have an Editor which shows the carriage returns and tabs, etc so I thought maybe there was something out of place perhaps.

You have changed the code a little bit to fix some previous errors. Would you mind re-posting the code and please identify the error line for us. PHP is funny about parse errors. It identifies a line by number where it senses the error, but it might be several lines back that the actual cause exists.

#11 shadowdemon

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 209 posts

Posted 01 April 2006 - 06:36 PM

View Postjlhaslip, on Apr 1 2006, 01:25 PM, said:

Sometimes an editor will plant invisible things in there. I happen to have an Editor which shows the carriage returns and tabs, etc so I thought maybe there was something out of place perhaps.

You have changed the code a little bit to fix some previous errors. Would you mind re-posting the code and please identify the error line for us. PHP is funny about parse errors. It identifies a line by number where it senses the error, but it might be several lines back that the actual cause exists.

sure no problem
<?php include ("header.php"); 
echo "Welcome to the construction site. Randomly we will update this place with stuff you can do. Currently we are offering you to make a building where you can make trade gold for ap or platinum for ap. The cost of this project is all 10k silver wood."; 

if ($stat[construction] <= 1) 
{ 
print 'Would you like to start the building';
echo '<a href="construction.php?action=construct">construct</a>';
}
if ($action == construct) {
print "you have started construction $stat[user]...<br><br>"; 
mysql_query("Update players Set construction=yes where id=stat[id] "); 
//a verification should be made if the player has the right amount of silver wood before making that query 
//else you'll end up with - numbers.. 
mysql_query("Update players Set silver wood = $stat[silverwood]-10000 where stat[id] "); 
mysql_query("Update players Set construction = stat[construction]+1 where stat[id] "); 
print "</table><br>"; 
print "Or you can always... <a href=city.php>go back</a>."; 
} 
} 
if ($stat[constructed] >= 2) 
{ 
$prices = mysql_query("select * from market"); 
$pa = mysql_fetch_array($prices); 
$plat_price = $pa[ap]; 
if ($action != buy) { 
print "Ap isn't always a stable-priced commodity... right now its $plat_price credits an ap. How much you want?"; 
print "<form method=post action=construction.php?action=buy>"; 
print "I want <input type=text name=plat> ap. <input type=submit value=Buy>"; 
print "</form>"; 
} else { 
$plat = str_replace("--","", $plat); 
$cost = ($plat * $plat_price); 
if ($cost > $stat[credits] || $plat <= 0) { 
print "You cant afford that! (<a href=pshop.php>back</a>)"; 
} else { 
mysql_query("update players set credits=credits-$cost where id=$stat[id]"); 
mysql_query("update players set ap=ap+$plat where id=$stat[id]"); 
print "You got <b>$plat</b> ap for <b>$cost</b> credits."; 
} 
} 

?> 

<? include ("footer.php"); ?> 

ignore those comments. i put those there to remind me of stuff that im gonna add.

Edited by shadowdemon, 01 April 2006 - 06:40 PM.


#12 jlhaslip

    Insert Custom Title Here

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,037 posts
  • Gender:Male
  • Location:Linux, DOS and Windows…the good, the bad and the ugly
  • Interests:http://jim.haslip.googlepages.com/home
  • myCENT:53.48
  • Spam Patrol

Posted 01 April 2006 - 06:43 PM

You will be having the same problem with this line:
print "Or you can always... <a href=city.php>go back</a>.";
as you had in the error Tyssen found. The use of double quotes is causing the parser to inspect that output for special characters and Variables. Implement the single quote or backslash techniques that Tyssen mentioned in the previous answer.
I would do it for you, but you will learn more from this exercise if you do it yourself. Have a look in the php references for the use of single / double quotes for printing.
Let me know if you are still having difficulties after an attempt or two and we'll fix you up.
Hint: single quotes around the whole thing and double quotes for the href =...

#13 shadowdemon

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 209 posts

Posted 01 April 2006 - 06:53 PM

View Postjlhaslip, on Apr 1 2006, 01:43 PM, said:

You will be having the same problem with this line:
print "Or you can always... <a href=city.php>go back</a>.";
as you had in the error Tyssen found. The use of double quotes is causing the parser to inspect that output for special characters and Variables. Implement the single quote or backslash techniques that Tyssen mentioned in the previous answer.
I would do it for you, but you will learn more from this exercise if you do it yourself. Have a look in the php references for the use of single / double quotes for printing.
Let me know if you are still having difficulties after an attempt or two and we'll fix you up.
Hint: single quotes around the whole thing and double quotes for the href =...

print 'Or you can always... <a href="city.php">go back</a>.'; 

like this

or like this
print 'Or you can always... "<a href=city.php>go back</a>".'; 

i checked the indexs in my php books and none said anything aboout double quotes or anything

on this one in another page of my site it says

	print "Or you can always... <a href=battle.php>go back</a>.";

is fine

#14 jlhaslip

    Insert Custom Title Here

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,037 posts
  • Gender:Male
  • Location:Linux, DOS and Windows…the good, the bad and the ugly
  • Interests:http://jim.haslip.googlepages.com/home
  • myCENT:53.48
  • Spam Patrol

Posted 01 April 2006 - 07:04 PM

<a href=battle.php>go back</a>
Without the quotes around the "battle.php" ???

#15 shadowdemon

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 209 posts

Posted 01 April 2006 - 07:07 PM

View Postjlhaslip, on Apr 1 2006, 02:04 PM, said:

<a href=battle.php>go back</a>
Without the quotes around the "battle.php" ???


yeah without the quotes. THsi is probly the most complicated parse error ive seen. I cant figure it out

#16 jlhaslip

    Insert Custom Title Here

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 5,037 posts
  • Gender:Male
  • Location:Linux, DOS and Windows…the good, the bad and the ugly
  • Interests:http://jim.haslip.googlepages.com/home
  • myCENT:53.48
  • Spam Patrol

Posted 01 April 2006 - 07:44 PM

print "Or you can always... <a href=city.php>go back</a>.";
 
Remove the period at the end of this line and see if that works. It might be trying to concatenate something there???

*edit* Browser troubles, fixing it up...

#17 shadowdemon

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 209 posts

Posted 01 April 2006 - 08:08 PM

View Postjlhaslip, on Apr 1 2006, 02:44 PM, said:

print "Or you can always... <a href=city.php>go back</a>.";
 
Remove the period at the end of this line and see if that works. It might be trying to concatenate something there???

*edit* Browser troubles, fixing it up...


no still parse error
sry about taking so long boredom troubles

#18 truefusion

    Coincidence is non-sequitur, therefore everything has a reason for its existence (except if they are eternal).

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 3,216 posts
  • Gender:Male
  • Location:No, not there. Not there either. Yes, you'll never figure it out.
  • Interests:God, Christianity.
  • myCENT:84.24

Posted 01 April 2006 - 09:39 PM

if ($action == construct) {
Put quotes around construct, see if that helps. Cause unless construct is a constant, it would need quotes, i guess.

And if that doesnt help, have you tried echo, rather than, print?

#19 shadowdemon

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 209 posts

Posted 01 April 2006 - 10:21 PM

View Posttruefusion, on Apr 1 2006, 04:39 PM, said:

if ($action == construct) {
Put quotes around construct, see if that helps. Cause unless construct is a constant, it would need quotes, i guess.

And if that doesnt help, have you tried echo, rather than, print?


with echo it doesnt work and with quotes it doesnt. Im getting so mad at this script. ARGGGH why wont it work.

#20 truefusion

    Coincidence is non-sequitur, therefore everything has a reason for its existence (except if they are eternal).

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 3,216 posts
  • Gender:Male
  • Location:No, not there. Not there either. Yes, you'll never figure it out.
  • Interests:God, Christianity.
  • myCENT:84.24

Posted 02 April 2006 - 12:36 AM

Try this:
<?php

include ("header.php");

echo "Welcome to the construction site. Randomly we will update this place with stuff you can do. Currently we are offering you to make a building where you can make trade gold for ap or platinum for ap. The cost of this project is all 10k silver wood.";

if ($stat[construction] <= 1){
print "Would you like to start the building";
echo "<a href=\"construction.php?action=construct\">construct</a>";
}
if ($action == "construct"){
print "you have started construction $stat[user]...<br /><br />";
mysql_query("Update players Set construction=yes where id=stat[id]");
//a verification should be made if the player has the right amount of silver wood before making that query
//else you'll end up with - numbers..
mysql_query("Update players Set silver wood = $stat[silverwood]-10000 where stat[id]");
mysql_query("Update players Set construction = stat[construction]+1 where stat[id]");
print "</table><br />";
print "Or you can always... <a href=\"city.php\">go back</a>.";
}

if ($stat[constructed] >= 2){
$prices = mysql_query("select * from market");
$pa = mysql_fetch_array($prices);
$plat_price = $pa[ap];
if ($action != "buy") {
print "Ap isn't always a stable-priced commodity... right now its $plat_price credits an ap. How much you want?";
print "<form method=\"post\" action=\"construction.php?action=buy\">";
print "I want <input type=\"text\" name=\"plat\"> ap. <input type=\"submit\" value=\"Buy\">";
print "</form>";
}
else {
$plat = str_replace("--","", $plat);
$cost = ($plat * $plat_price);
if ($cost > $stat[credits] || $plat <= 0) {
print "You cant afford that! (<a href=\"pshop.php\">back</a>)";
}
else {
mysql_query("update players set credits=credits-$cost where id=$stat[id]");
mysql_query("update players set ap=ap+$plat where id=$stat[id]");
print "You got <b>$plat</b> ap for <b>$cost</b> credits.";
}
}
}

include ("footer.php");

?>

Edited by truefusion, 02 April 2006 - 12:42 AM.


#21 shadowdemon

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 209 posts

Posted 02 April 2006 - 01:48 AM

Well i asked a old firend of mine on another site to help and he figured it out.




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users