Page 1 of 1

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

Posted: Thu Aug 01, 2002 8:16 pm
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;
?>

Posted: Thu Aug 01, 2002 9:53 pm
by daemorhedron
You haven't closed your switch statement with a } for one.

you need: }

Posted: Thu Aug 01, 2002 9:53 pm
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;
?>

Posted: Thu Aug 01, 2002 10:02 pm
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;
}

lol ty

Posted: Fri Aug 02, 2002 10:22 am
by pb2ya
thanx guys, i feel so stupid.

Posted: Fri Aug 02, 2002 11:08 am
by JPlush76
doesn't suck when you miss the most obvious things?

I do that often :)