Page 1 of 1

Showing table with msql/php

Posted: Wed Jun 16, 2010 6:49 pm
by btr4
I'm trying to create a staff management system for a website, and I have the mysql database set up with the fields "satffid, staffname, staffbio". I have a system to take user-defined values from a form, and insert it into the database. It works. Now, when I try to create a table that shows all the staff members (name only), the table does not appear. Code is below, and thanks ahead of time for any help.

Code: Select all

<?php require_once('../Connections/hcc.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_rsStaff = "-1";
if (isset($_GET['id'])) {
  $colname_rsStaff = $_GET['id'];
}
mysql_select_db($database_hcc, $hcc);
$query_rsStaff = sprintf("SELECT * FROM cms_staff WHERE staffid = %s", ($colname_rsStaff, "int"));
$rsStaff = mysql_query($query_rsStaff, $hcc) or die(mysql_error());
$row_rsStaff = mysql_fetch_assoc($rsStaff);
$totalRows_rsStaff = mysql_num_rows($rsStaff);
?>
<!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"><!-- InstanceBegin template="/Templates/admin_temp.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Link Management System</title>
<!-- InstanceEndEditable -->
<link href="../style/admin_style.css" rel="stylesheet" type="text/css" />
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
</head>

<body>
<div id="wrapper">
<div id="header">
  <p>Control Panel</p>
  <p>&nbsp;</p>
</div>
<div id="navigation">
<ul id="mainav">
<li></li>
<li></li>
<li><a href="logout.php">logout</a></li>
<li id="front"><a href="../index.php" target="_blank">front</a></li>
</ul>
</div>
<div id="container"><!-- InstanceBeginEditable name="edit_content" -->
  <p id="ptitle">Manage Staff</p>
  <p>&nbsp;</p>
  <p></p>
  <?php if ($totalRows_rsStaff > 0) { // Show if recordset not empty ?>
    <table border="0" cellpadding="0" cellspacing="0" id="tblrepeat">
      <tr>
        <th>Staff Name</th>
        <th>Remove</th>
        <th>Edit</th>
      </tr>
      <?php do { ?>
        <tr>
          <td><?php echo $row_rsStaff['staffname']; ?></td>
          <td><a href="staff_delete.php?id=<?php echo $row_rsStaff['staffid']; ?>">Remove</a></td>
          <td><a href="staff_edit.php?id=<?php echo $row_rsStaff['staffid']; ?>">Edit</a></td>
        </tr>
        <?php } while ($row_rsStaff = mysql_fetch_assoc($rsStaff)); ?>
    </table>
    <?php } // Show if recordset not empty ?>
  <?php if ($totalRows_rsStaff == 0) { // Show if recordset empty ?>
  <p>Sorry, there are no records matching your searching criteria.</p>
  <?php } // Show if recordset empty ?>
<a href="staff_add.php">Add Staff</a>
<!-- InstanceEndEditable --></div>
<div id="footer"><p>© Web Designer Justin Bell</p></div>
</div>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($rsStaff);
?>