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
pb2ya
Forum Commoner
Posts: 42 Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:
Post
by pb2ya » Thu Aug 01, 2002 8:16 pm
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ї'action']))
{
$_GETї'action'] = 0;
}
$action = $_GETї'action'];
if (empty($_GETї'ID']))
{
$_GETї'ID'] = 0;
}
$ID = $_GETї'ID'];
switch($action)
{
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))
{
$id = $rї"ID"];
$un = $rї"username"];
$pass = $rї"password"];
$admin = $rї'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>";
}
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 » Thu Aug 01, 2002 9:53 pm
You haven't closed your switch statement with a } for one.
AVATAr
Forum Regular
Posts: 524 Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:
Post
by AVATAr » Thu Aug 01, 2002 9:53 pm
try this...
Code: Select all
<?php
if (empty($_GETї'action']))
{
$_GETї'action'] = 0;
}
$action = $_GETї'action'];
if (empty($_GETї'ID']))
{
$_GETї'ID'] = 0;
}
$ID = $_GETї'ID'];
switch($action)
{
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))
{
$id = $rї"ID"];
$un = $rї"username"];
$pass = $rї"password"];
$admin = $rї'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>";
}
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 » Thu Aug 01, 2002 10:02 pm
{} 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:
Post
by pb2ya » Fri Aug 02, 2002 10:22 am
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 » Fri Aug 02, 2002 11:08 am
doesn't suck when you miss the most obvious things?
I do that often