PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Parody
Forum Contributor
Posts: 252 Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain
Post
by Parody » Mon May 30, 2005 2:34 pm
This is my script:
Code: Select all
<div align="e;center"e;></div>
<?php
$rand = rand(200, 367);
$link = mysql_connect("e;localhost"e;, "e;*****"e;, "e;******"e;;
mysql_select_db ("e;stats"e;)or die ("e;Could not select database"e;);
$query = “SELECT cstat FROM stats WHERE username=$_SESSIONї'username']”;
$result = mysql_query($query);
while ($row = mysql_fetch_array($result));
mysql_close();
$chancemoney = $rowї‘cstat’] * 3
$moneyget = $rand + $chancemoney
$rand2 = rand(0,100)
$dvd = $rowї‘cstat’] + 10
if ( $dvd > $rand2 )
(
$success = 1;
)
else
(
$success = 0;
)
switch ($success) {
case "e;0"e;:
print "e;You failed and were caught by the cops!"e;;
break;
case "e;1"e;:
print "e;You were successful and got /$"e;$moneyget"e;"e; $successful = 1;
break;
}
if ( $successful == 1 )
($link = mysql_connect("e;localhost"e;, "e;*****"e;, "e;******"e;;
mysql_select_db ("e;stats"e;)or die ("e;Could not select database"e;);
$money = “SELECT money FROM stats WHERE username=$_SESSIONї'username']”;
$result = mysql_query($query);
while ($row = mysql_fetch_array($result));
mysql_query($money);
$money = $rowї‘money’]
$updatedmoney = $money + "e;$getmoney"e;
$updatedmoney1="e;UPDATE stats SET money= "e;$updatedmoney"e; WHERE username='$_SESSIONї'username']'"e;;
$cstat = “SELECT cstat FROM stats WHERE username=$_SESSIONї'username']”;
$result = mysql_query($query);
while ($row = mysql_fetch_array($result));
mysql_query($cstat);
$cstat1 = $rowї‘cstat’]
$updatedcstat = $cstat1 + 0.1
$updatedcstat1="e;UPDATE stats SET cstat= "e;$updatedcstat"e; WHERE username='$_SESSIONї'username']'"e;;
mysql_query($updatedcstat1);
mysql_close();
)
else
(
);
?>
The ***** is my username
****** is my password
This is the error I get:
Parse error: syntax error, unexpected ';' in c:\program files\apache group\Apache\htdocs\cddvd.php on line 4
I checked the rand function and it definitely needs the ; (I know that sounds stupid but I had to check)
Make any sense?
When I took away the ; I got this:
Parse error: syntax error, unexpected T_VARIABLE in c:\program files\apache group\Apache\htdocs\cddvd.php on line 4
Any ideas
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Mon May 30, 2005 2:39 pm
First of all, use php tags for php code
Second of all, check this out:
Code: Select all
$link = mysql_connect("e;localhost"e;, "e;*****"e;, "e;******"e;;
Anything missing?
Parse errors are tricky things: sometimes they'll be easy to detect because the line the error it returns will be the line the problem is one... but other times it isn't. For instance, I once forgot to close a quote: it didn't throw the error until, like, another 300 lines (when I next used a quote).
Parody
Forum Contributor
Posts: 252 Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain
Post
by Parody » Mon May 30, 2005 2:40 pm
What is missing?
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Mon May 30, 2005 2:44 pm
The ending parentheses. It should be:
Code: Select all
$link = mysql_connect("localhost", "*****", "******");
This is what the parser is thinking:
Code: Select all
Hmm... a function! There's the starting parentheses. Coolio.
Parsed "e;localhost"e;
Parsed "e;*****"e;
Parsed "e;*******"e;
Oh wow! Where'd this semicolon come from? I need an ending parentheses!
And then it echos the "Unexpected Semicolon"
Parody
Forum Contributor
Posts: 252 Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain
Post
by Parody » Mon May 30, 2005 2:45 pm
Thanks, I didn't see
Parody
Forum Contributor
Posts: 252 Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain
Post
by Parody » Mon May 30, 2005 2:47 pm
Still get the this error:
Parse error: syntax error, unexpected T_VARIABLE in c:\program files\apache group\Apache\htdocs\cddvd.php on line 4
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Mon May 30, 2005 2:49 pm
Did you add back the semicolon you deleted earlier?
Parody
Forum Contributor
Posts: 252 Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain
Post
by Parody » Mon May 30, 2005 2:50 pm
No, I just put it back in and now I have this error:
Parse error: syntax error, unexpected T_STRING in c:\program files\apache group\Apache\htdocs\cddvd.php on line 6
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Mon May 30, 2005 2:52 pm
::Looks::
What the h*** are you editing your PHP with?
Code: Select all
$query = “SELECT cstat FROM stats WHERE username=$_SESSION['username']”;
This could only be the nefarious work of Microsoft Word's smartquotes. Change it to this:
Code: Select all
$query = "SELECT cstat FROM stats WHERE username={$_SESSION['username']}";
And put some proper input validation in the SQL Query!
Parody
Forum Contributor
Posts: 252 Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain
Post
by Parody » Mon May 30, 2005 2:54 pm
The only reason I used ****** was because I need to keep my password safe.
Parody
Forum Contributor
Posts: 252 Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain
Post
by Parody » Mon May 30, 2005 2:56 pm
DAMN CODE!
I now have this error:
Parse error: syntax error, unexpected T_VARIABLE in c:\program files\apache group\Apache\htdocs\cddvd.php on line 11
This is getting annoying
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Mon May 30, 2005 3:06 pm
You know, these syntax errors, you have to figure 'em out yourself. Now take a look at the code, and see what's wrong...
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Mon May 30, 2005 4:17 pm
son you gotta add a semi collon after your lines
Code: Select all
$chancemoney = $row[‘cstat’] * 3
$moneyget = $rand + $chancemoney
$rand2 = rand(0,100)
$dvd = $row[‘cstat’] + 10
after you assign a variable you gotta put a semi collon after the line because thats how php knows that your done with that line. if you forget a semi collon php dies with a parse error message and a line number, the line number is the line after the line you forgot the semi collon.
there are more lines you forgot to do that with but ill leave that for you to figure out
Ambush Commander
DevNet Master
Posts: 3698 Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US
Post
by Ambush Commander » Mon May 30, 2005 4:29 pm
Don't use microsoft word to edit your PHP. PHP only supports double quotes ( " ), single quote ( ' ) and
heredoc for strings.
Skara
Forum Regular
Posts: 703 Joined: Sat Mar 12, 2005 7:13 pm
Location: US
Post
by Skara » Mon May 30, 2005 4:31 pm
Indeed. Without downloading anything, the best code editor on your computer is notepad.