Page 1 of 2

Make Any Sense?

Posted: Mon May 30, 2005 2:34 pm
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 :?:

Posted: Mon May 30, 2005 2:39 pm
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).

Posted: Mon May 30, 2005 2:40 pm
by Parody
What is missing?

Posted: Mon May 30, 2005 2:44 pm
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"

Posted: Mon May 30, 2005 2:45 pm
by Parody
Thanks, I didn't see :D :D

Posted: Mon May 30, 2005 2:47 pm
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

Posted: Mon May 30, 2005 2:49 pm
by Ambush Commander
Did you add back the semicolon you deleted earlier?

Posted: Mon May 30, 2005 2:50 pm
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

Posted: Mon May 30, 2005 2:52 pm
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!

Posted: Mon May 30, 2005 2:54 pm
by Parody
The only reason I used ****** was because I need to keep my password safe.

Posted: Mon May 30, 2005 2:56 pm
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 :(

Posted: Mon May 30, 2005 3:06 pm
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...

Posted: Mon May 30, 2005 4:17 pm
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

Posted: Mon May 30, 2005 4:29 pm
by Ambush Commander
Don't use microsoft word to edit your PHP. PHP only supports double quotes ( " ), single quote ( ' ) and heredocfor strings.

Posted: Mon May 30, 2005 4:31 pm
by Skara
Indeed. Without downloading anything, the best code editor on your computer is notepad. :|