Jump to content
xisto Community
Sign in to follow this  
shadowdemon

A Parse Error Problem

Recommended Posts

<?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

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 (see edit history)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

now i get thisParse error: parse error in /home/www/dancha42.madpage.com/construction.php on line 20i hate parse errors. im gonna try and figure it out myself but if you what to fix your suggestions are welcomed

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

 

And for this:

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 (see edit history)

Share this post


Link to post
Share on other sites

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


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 (see edit history)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 (see edit history)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.