Forum Moderators: coopster
this is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update Users</title>
</head>
<body>
</body>
<?php
global $gid;
$gname = $_GET['x'] ;
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = 'dba';
$database = 'saberplex';
$table = 'user_groups';
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($database))
die("Can't select database");
$result = mysql_query("SELECT * FROM {$table} WHERE ug_name like '".$gname."'");
if (!$result) { die("Query to show fields from table failed");
}
else
{
while ($row = mysql_fetch_array($result) )
{
$groupcode = $row['ug_code'];
$groupname = $row['ug_name'];
$gid = $row['ug_id'];
}
?>
<form name="updateform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<tr>Group Code:<INPUT TYPE=text NAME="txtgcode" SIZE=20 class=textbox value="<?php echo $groupcode; ?>"></tr>
<tr>Group Name:<INPUT TYPE=select NAME="cmbgname" SIZE=20 class=combobox value="<?php echo $groupname; ?>"></tr>
<tr><input type=submit name=btnupdate value="Update" /></tr>
<tr><a href="usergroups.php"><input type=submit name=btncancel value="Cancel" /></a></tr>
</form>
<?php
if(isset($_POST['btnupdate']))
{
$groupcode = $_POST['txtgcode'];
$groupname = $_POST['cmbgname'];
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($database))
die("Can't select database");
$result=mysql_query("UPDATE user_groups SET ug_code='$groupcode', ug_name='$groupname' WHERE ug_id='$gid'")
or die("MYSQL Returned: " . mysql_error());
echo "The User Details have been updated. Thank you!";
}
?>
</html> ///////////////////////this is the line where I get the error