Page 1 of 1

if loop get action error

Posted: Fri Dec 17, 2004 8:35 am
by sn202
using an if loop to carryout an action, depending on the link clicked but i'm getting "Parse error: parse error in /home/sn202/public_html/useradmin.php on line 17" error which is the line "if ($action="show") {" any ideas wot wrong with this...?

Code: Select all

<?php
<?php
$self =			$_SERVER['PHP_SELF'];
			$username = $_POST['username'];
			$role = $_POST['role'];
			$action = $_GET['action'];
#connect to MYSQL
$conn = @mysql_connect( "linuxproj", "sn202", "e1420518" )
				or die( "could not connect" );
#select the specified database
$rs = @mysql_select_db ( "db_sn202", $conn )
			or die( "could not select database" );

$action=(isset($_GET['action']) ? $_GET['action'] : "")

#runs slected PHP function
#show users
if ($action="show") {
#create the sql query
$sql="select * from users";
#exercute the query
$rs = mysql_query( $sql, $conn )
	  or die( "could not exercute query" );
#write data
while( $row = mysql_fetch_array( $rs ) )
{
	echo( "ID: " . $row["id"] );
	echo( "Username: " . $row["username"];
	echo( "role: " . $row["role"] . "<br>");
} 

#add user
if ($action="add") { 
if( $username and $role ) #ensure values exist
{ #create the sql query
$sql="insert into users (username, role)
		  values ( $username, "$role" )";
#exercute the query
$rs = mysql_query( $sql, $conn )
	  or die( "could not exercute query" );
#confirm the added record details
if($rs) { echo( "record added:$username $role" ); }
}

#delete user
if ($action="delete") { 
if( $username ) #ensure values exist
{ #create the sql query
$sql="delete from users where username=$username";
#exercute the query
$rs = mysql_query( $sql, $conn )
	  or die( "could not exercute query" );
#confirm the added record details
if($rs) { echo( "record deleted:$username" ); }
}

#update user detailes
if ($action="update") { 
if( $username ) #ensure values exist
{ #create the sql query
$sql="update users set username = $username where username = $oldusername";
#exercute the query
$rs = mysql_query( $sql, $conn )
	  or die( "could not exercute query" );
$sql="update users set role = $role where username = $username";
#exercute the query
$rs = mysql_query( $sql, $conn )
	  or die( "could not exercute query" );
#confirm the added record details
if($rs) { echo( "record updated:$userid $username $role" ); }
}
?>
?>

Posted: Fri Dec 17, 2004 8:49 am
by []InTeR[]
Maybe:
if ($action=="show") {

and a }
before:
#add user
if ($action="add") {