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

Post by Parody »

I'm using Dreamweaver, I just mess up on the ; and ().

One last problem:

Code: Select all

if( $dvd > $rand2 )
(
$success = 1;
)
else
(
$success = 0;
)
The first line of that code is line 14.

The error I get:

Parse error: syntax error, unexpected ';' in c:\program files\apache group\Apache\htdocs\cddvd.php on line 16
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Dreamweaver sucks ass too.

You need to use curly brackets, not parentheses:

Code: Select all

if( $dvd > $rand2 )
{
$success = 1;
}
else
{
$success = 0;
}
Though this is a really really lame way to do this, no offense. I'll shorten by steps.

First, no need for brackets unless you want them for single statements.

Code: Select all

if ($dvd > $rand2) $success = 1;
else $success = 0;
Second, for a simple if else that sets a single variable, use a ternary operator:

Code: Select all

$success = ($dvd > $rand2) ? 1 : 0;
Third, since ($dvd > $rand2) evaluates to true or false anyway...

Code: Select all

$success = $dvd > $rand2;
;)
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

agreed on the DW statement...you could however use Homesite which is bundled with DW which is a fine editor...in fact my editor of choice simply because of the multiple resource tabs...

not to take this thread off topic or anything 8O
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Actually, I prefer to use brackets, because it's easy to forget to add them later if you want to add extra commands.

Code: Select all

$yes = $_POST['yes'];
if ($yes)
    $command = 0;
$bang = $command;
$foo = $command & $yes;
to

Code: Select all

$yes = $_POST['yes'];
if ($yes)
    $command = 0;
    $piffle = 1;
$bang = $command;
$foo = $command & $yes;
Won't do what you expect.
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Hopefully this will be the last thing I ask on this topic because I know you are getting annoyed at my stupidity.

The middle line is line 20:

Code: Select all

case "1":
    print "You were successful and got /$"$moneyget"";
    break;
Parse error: syntax error, unexpected T_VARIABLE in c:\program files\apache group\Apache\htdocs\cddvd.php on line 20
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Post by Parody »

Can someone give me a link to a site which explains all the errors simply?

I think it would save us all a lot of time :D
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Code: Select all

print "You were successful and got /$".$moneyget."";
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Usually, Parse errors aren't much help, you just tend to get a feel of them and then you don't worry about Parse errors. You'd be better off executing the code as often as possible to make sure you didn't make a parse error (one of the great advantages of PHP)
Post Reply