Make Any Sense?

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

Make Any Sense?

Post by Parody »

This is my script:

Code: Select all

<div align=&quote;center&quote;></div>
<?php
$rand = rand(200, 367);
$link = mysql_connect(&quote;localhost&quote;, &quote;*****&quote;, &quote;******&quote;;
mysql_select_db (&quote;stats&quote;)or die (&quote;Could not select database&quote;);
$query = “SELECT cstat FROM stats WHERE username=$_SESSION&#1111;'username']”;
$result = mysql_query($query);
while ($row = mysql_fetch_array($result));
mysql_close();
$chancemoney = $row&#1111;‘cstat’] * 3
$moneyget = $rand + $chancemoney
$rand2 = rand(0,100)
$dvd = $row&#1111;‘cstat’] + 10
if ( $dvd > $rand2 )
(
$success = 1;
)
else
(
$success = 0;
) 
switch ($success) {
case &quote;0&quote;:
    print &quote;You failed and were caught by the cops!&quote;;
    break;
case &quote;1&quote;:
    print &quote;You were successful and got /$&quote;$moneyget&quote;&quote; $successful = 1;
    break;			
  }
if ( $successful == 1 )
($link = mysql_connect(&quote;localhost&quote;, &quote;*****&quote;, &quote;******&quote;;   
mysql_select_db (&quote;stats&quote;)or die (&quote;Could not select database&quote;);
$money = “SELECT money FROM stats WHERE username=$_SESSION&#1111;'username']”;
$result = mysql_query($query);
while ($row = mysql_fetch_array($result));
mysql_query($money);
$money = $row&#1111;‘money’]
$updatedmoney = $money + &quote;$getmoney&quote;
$updatedmoney1=&quote;UPDATE stats SET money= &quote;$updatedmoney&quote; WHERE username='$_SESSION&#1111;'username']'&quote;;
$cstat = “SELECT cstat FROM stats WHERE username=$_SESSION&#1111;'username']”;
$result = mysql_query($query);
while ($row = mysql_fetch_array($result));
mysql_query($cstat);
$cstat1 = $row&#1111;‘cstat’]
$updatedcstat = $cstat1 + 0.1
$updatedcstat1=&quote;UPDATE stats SET cstat= &quote;$updatedcstat&quote; WHERE username='$_SESSION&#1111;'username']'&quote;;
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 :?:
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

First of all, use php tags for php code

Second of all, check this out:

Code: Select all

$link = mysql_connect(&quote;localhost&quote;, &quote;*****&quote;, &quote;******&quote;;
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 »

What is missing?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

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 &quote;localhost&quote;
Parsed &quote;*****&quote;
Parsed &quote;*******&quote;
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 »

Thanks, I didn't see :D :D
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

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
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

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 »

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
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

::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 »

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 »

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 :(
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

You know, these syntax errors, you have to figure 'em out yourself. Now take a look at the code, and see what's wrong...
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

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
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Don't use microsoft word to edit your PHP. PHP only supports double quotes ( " ), single quote ( ' ) and heredocfor strings.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Indeed. Without downloading anything, the best code editor on your computer is notepad. :|
Post Reply