WHY WONT YOU WORK!!!???!!!???

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
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

WHY WONT YOU WORK!!!???!!!???

Post by pb2ya »

yes, im still a n00b. plz help me fix this. ts purpose is to list users in the database and let admins delete members.
error:
Parse error: parse error, unexpected '}' in c:\program files\apache group\apache\htdocs\test.php on line 29

Code: Select all

<?php
if (empty($_GET&#1111;'action']))
&#123;
        $_GET&#1111;'action'] = 0;
&#125;
$action = $_GET&#1111;'action'];
if (empty($_GET&#1111;'ID']))
&#123;
        $_GET&#1111;'ID'] = 0;
&#125;
$ID = $_GET&#1111;'ID'];
switch($action)
&#123;
case "default":
$conn = mysql_connect("localhost", "", "");
mysql_select_db("guestbook", $conn);
$query = "SELECT * FROM users";
$result = mysql_query($query,$conn)or die("query failed");
?>
<table border="3">
<tr>
 <th>User#</th>
 <th>Username</th>
 <th>Password</th>
 <th>Admin Status</th>
 <th>Admin Function</th>
</tr>
<?php
while($r=mysql_fetch_array($result))
&#123;
    $id = $r&#1111;"ID"];
    $un = $r&#1111;"username"];
    $pass = $r&#1111;"password"];
    $admin = $r&#1111;'admin'];
    echo "<tr><td>$id</td><td>$un</td><td>$pass</td><td>$admin</td>
          <td><a href="?action=delete&ID=" . $ID . "">Delete user</a></td>
          </tr>";
&#125;
break;
case "delete":
$conn = mysql_connect("localhost","", "") or die ("cant connect");
$query = "delete from users where ID = '$ID'";
mysql_select_db("guestbook",$conn) or die ("cant change");
$result=mysql_query($query ,$conn) or die ("cant do it");
break;
?>
daemorhedron
Forum Commoner
Posts: 52
Joined: Tue Jul 23, 2002 11:03 am

Post by daemorhedron »

You haven't closed your switch statement with a } for one.
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

you need: }

Post by AVATAr »

try this...

Code: Select all

<?php
if (empty($_GET&#1111;'action']))
&#123;
        $_GET&#1111;'action'] = 0;
&#125;

$action = $_GET&#1111;'action'];

if (empty($_GET&#1111;'ID']))
&#123;
        $_GET&#1111;'ID'] = 0;
&#125;

$ID = $_GET&#1111;'ID'];

switch($action)
&#123;
case "default":
       &#123;$conn = mysql_connect("localhost", "", "");
        mysql_select_db("guestbook", $conn);
        $query = "SELECT * FROM users";
        $result = mysql_query($query,$conn)or die("query failed");
        ?>
        <table border="3">
        <tr>
        <th>User#</th>
        <th>Username</th>
        <th>Password</th>
        <th>Admin Status</th>
        <th>Admin Function</th>
        </tr>
        <?php
        while($r=mysql_fetch_array($result))
        &#123;
            $id = $r&#1111;"ID"];
            $un = $r&#1111;"username"];
            $pass = $r&#1111;"password"];
            $admin = $r&#1111;'admin'];
            echo "<tr><td>$id</td><td>$un</td><td>$pass</td><td>$admin</td>
                  <td><a href="?action=delete&ID=" . $ID . "">Delete user</a></td>
                  </tr>";
        &#125;
        break;
        &#125;
case "delete":
      &#123;  $conn = mysql_connect("localhost","", "") or die ("cant connect");
        $query = "delete from users where ID = '$ID'";
        mysql_select_db("guestbook",$conn) or die ("cant change");
        $result=mysql_query($query ,$conn) or die ("cant do it");
        break;
      &#125;
     &#125;
?>
daemorhedron
Forum Commoner
Posts: 52
Joined: Tue Jul 23, 2002 11:03 am

Post by daemorhedron »

{} are only needed between start and end of the swtich, and are not needed between case statements, as the break construct indicates termination of a block. From php manual :

switch ($i) {
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
break;
case 2:
print "i equals 2";
break;
}
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

lol ty

Post by pb2ya »

thanx guys, i feel so stupid.
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

doesn't suck when you miss the most obvious things?

I do that often :)
Post Reply