I can't understand brackets

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

Post Reply
Altec88
Forum Newbie
Posts: 7
Joined: Mon Feb 20, 2006 8:53 pm

I can't understand brackets

Post by Altec88 »

Ok, I'm trying to make a simple username,password system, and I need to know where the { } marks go. This is my first time with php. Here is the code:

Code: Select all

<?php
$found=0;
$filefopen("members.dat", "r");
(!feof($file))
$line=fgets($file,255);
$line=chop($line);
$field=split("#",$line,6);
if($username==$field[0])
$found=1;
if(password!=$field[1])
print "<h2>Wrong Password</h2>";
die();
if($found==0)
{print "<h2>Username does not exist</h2>";
die();
?>
Thanks a ton! I don't understand these {} marks.

This part is supposed to authenticate a user before displaying the page.
pennythetuff
Forum Newbie
Posts: 22
Joined: Sun Feb 19, 2006 6:05 pm
Location: Kokomo, Indiana

Post by pennythetuff »

Code: Select all

<?php
$found=0;
$file = fopen("members.dat", "r");
while(!feof($file)) {
  $line=fgets($file,255);
  $line=rtrim($line);
  $field=split("#",$line,6);
  if($username==$field[0]) {
    $found=1;
  if($password!=$field[1]) {
    echo "<h2>Wrong Password</h2>";
    die();
  }
  if($found==0) {
    echo "<h2>Username does not exist</h2>";
    die();
  }
}
?>
There's where the brackets would go, and I changed your first if-statement into a while loop to loop through each line.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Brackets are used to encapsulate code in a control structure. Control structures include statements such as IF ELSE ELSEIF WHILE FOR SWITCH and a few others. Download the PHP reference manual from php.net or do a google search for PHP Tutorials to learn more.

Code: Select all

// $x == $y means "is equal to"
if ($x == $y) {
  // if this condition is true
  // execute the code in the brackets
}
Post Reply