Jump to content

Several different procedures being used on the same form. Very Complicated!


paddyhaig

Recommended Posts

I have a form/mySQL data table that I am trying to delete data from, add data too and edit the data via fields on the same page. I will try to be a little clearer.

Here is a graphic of the table/form populated with some user data:

 

form_table.jpg

 

Here is a graphic of the same form populated with some more user data:

 

form_data_more_data.jpg

 

Here is what comes up when I click on the (Add/User) link:

 

add-user.jpg

 

Here's what comes up when I click on the (Edit) row

 

edit.jpg

 

What I am trying to do, is combine all the procedures onto the same page.

The actual form fields on the table do nothing at present.

 

As it is, everything works, only I think it could be a little neater if it were all done via the same interface. Does anyone have any realistic ideas that might help.

I have all the present code if anyone can help.

Link to comment
Share on other sites

Here is the code being used at present:

 

For the main form and table:

 

<?php require_once('../Connections/Concierge.php'); ?>
<?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;
}
}

mysql_select_db($database_Concierge, $Concierge);
$query_rsAuth = "SELECT * FROM auth ORDER BY id ASC";
$rsAuth = mysql_query($query_rsAuth, $Concierge) or die(mysql_error());
$row_rsAuth = mysql_fetch_assoc($rsAuth);
$totalRows_rsAuth = mysql_num_rows($rsAuth);
?>
<?php
$id = "id";
$forename = "forename";
$surname = "surname";
$username = "username";
$password = "password";
$privilege = "privilege";
$administrator = "administrator";
$manager = "manager";
$receptionist = "receptionist";
?>
<?php include("cookie_security.inc"); ?>
<!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>Concierge Edit staff member</title>

<link href="../includes/primary_layout.css" rel="stylesheet" type="text/css"/>
<style type="text/css">
#center_box {
height: 223px;
width: 626px;
overflow:auto;
padding: 0px;
left: 139px;
top: 110px;
position: absolute;
margin-top: -55px;
margin-right: auto;
margin-bottom: auto;
margin-left: -65px;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="large-blue-box">
<div id="center_box">
    
<div id="form">
  <div align="center">
    <table width="98%" border="1" cellpadding="0" cellspacing="0">
      <tr>
        <th colspan="7">* Indicates required field. Please delete  * and fill form field with appropriate information.</th>
        </tr>
      <tr>
        <th width="16%">Add/Remove</th>
        <th colspan="2">First/Last Names</th>
        <th colspan="2">Login/Password</th>
        <th width="20%">Privilege</th>
        <th width="6%">Submit/Edit</th>
        </tr>
      <tr>
      
            <!--  This is hidden -->          
<input type="hidden" name="<?php $id ?>" id="id_number"/>
            <!--  End of hidden -->
      
        <td><div align="center"><a href="create_staff_member.php">(AddUser)</a></div></td>
        
<!--  <th>id</th> --> 

        <td width="10%"><div align="center">
          <input name="<?php $forename ?>" type="text" id="forename" value="*" size="9" maxlength="15" />
        </div></td>
        <td width="15%"><input name="<?php $surname ?>" type="text" id="surname" value="*" size="9" maxlength="15" /></td>
        <td width="16%"><div align="center">
          <input name="<?php $login ?>" type="text" id="username" value="*" size="9" maxlength="15" />
        </div></td>
        <td width="17%"><input name="<?php $password ?>" type="password" id="password" value="*" size="9" maxlength="15" /></td>
<!--    <th>password</th> -->
        <td><div align="center">
          <select name="privilege" id="privilege">
            <option value="<?php $privilege ?>">*Privilege</option>
            <option value="<?php $administrator ?>">Administrator</option>
            <option value="<?php $manager ?>">Manager</option>
            <option value="<?php $receptionist ?>">Receptionist</option>
          </select>
        </div></td>
<!--    <th>login_time</th> -->
<!--    <th>logout_time</th> -->
        <td><div align="center"><a href="nowhere.php">(Submit)</a></div></td>
      </tr>
      <?php do { ?>
        <tr>
          <td><div align="center"><a href="delete_user.php?id=<?php echo $row_rsAuth['id']; ?>">(Remove)</a></div></td>
<!--      <td><?php $row_rsAuth['id']; ?></td> -->
          <td colspan="2"><div align="center"><?php echo $row_rsAuth['first_name']; ?> <?php echo $row_rsAuth['last_name']; ?></div>            <div align="center"></div></td>
          <td colspan="2"><div align="center"><?php echo $row_rsAuth['login']; ?></div></td>
<!--      <td><?php $row_rsAuth['password']; ?></td> -->
          <td><div align="center"><?php echo $row_rsAuth['privilege']; ?></div></td>
<!--      <td><?php $row_rsAuth['login_time']; ?></td> -->
<!--      <td><?php $row_rsAuth['logout_time']; ?></td> -->
          <td><div align="center"><a href="form_update.php?id=<?php echo $row_rsAuth['id']; ?>">(Edit)</a></div></td>
        </tr>
        <?php } while ($row_rsAuth = mysql_fetch_assoc($rsAuth)); ?>
    </table>
  </div>
</div>
<p align="center"> </p>
  </div>
  <div id="form11"><a href="staff_management.php"><img src="../graphics/general/index_button.gif" width="180" height="28" /></a>
    
</div>  
</div>

<?php include("../includes/footer.inc"); ?>
  
</div>
</body>
</html>



<?php
mysql_free_result($rsAuth);
?>

 

For the (Edit/User)

 

<?php require_once('../Connections/Concierge.php'); ?>
<?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;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO auth (first_name, last_name, login, password, privilege) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['forename'], "text"),
                       GetSQLValueString($_POST['surname'], "text"),
                       GetSQLValueString($_POST['login'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['privilege'], "text"));

  mysql_select_db($database_Concierge, $Concierge);
  $Result1 = mysql_query($insertSQL, $Concierge) or die(mysql_error());

  $insertGoTo = "edit_staff_member.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_Concierge, $Concierge);
$query_rsAuth = "SELECT * FROM auth ORDER BY id ASC";
$rsAuth = mysql_query($query_rsAuth, $Concierge) or die(mysql_error());
$row_rsAuth = mysql_fetch_assoc($rsAuth);
$totalRows_rsAuth = mysql_num_rows($rsAuth);
?>
<!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>Create Staff Member</title>
<link href="../includes/primary_layout.css" rel="stylesheet" type="text/css"/>
<style type="text/css">
#center_box {
height: 184px;
width: 145px;
padding: 0px;
left: 156px;
top: 121px;
position: absolute;
margin-top: -55px;
margin-right: auto;
margin-bottom: auto;
margin-left: -65px;
}
#input_form {
height: 315px;
width: 261px;
padding: 0px;
left: 141px;
top: 140px;
position: absolute;
margin-top: -55px;
margin-right: auto;
margin-bottom: auto;
margin-left: -65px;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="small-blue-box">

  <form id="input_form" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  
    <table width="234" border="0" cellpadding="0" cellspacing="0">
      <tr bgcolor="#283a86">
        <th width="95" scope="row">First Name </th>
        <td width="133"><input name="forename" type="text" id="forename" size="19" /></td>
      </tr>
      <tr bgcolor="#283a86">
        <th scope="row">Last Name</th>
        <td><input name="surname" type="text" id="surname" size="19" /></td>
      </tr>
      <tr bgcolor="#283a86">
        <th scope="row">User Name</th>
        <td><input name="login" type="text" id="login" size="19" /></td>
      </tr>
      <tr bgcolor="#283a86">
        <th scope="row">Password</th>
        <td><input name="password" type="password" id="password" size="19" /></td>
      </tr>
      <tr bgcolor="#283a86">
        <th scope="row">Privilege</th>
        <td><select name="privilege" id="privilege">
          <option value="receptionist">Receptionist</option>
          <option value="manager">Manager</option>
          <option value="administrator">Administrator</option>
          <option value="suspended">Suspended</option>
        </select></td>
      </tr>
    </table>
    <div align="">
      <input type="submit" name="submit" id="submit" value="Submit" />
      <input type="hidden" name="MM_insert" value="form1" />
    </div>
  </form>


</div>

</body>
</html>
<?php
mysql_free_result($rsAuth);
?>

 

For the (Submit/Edit)

 

<?php require_once('../Connections/Concierge.php'); ?>
<?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;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE auth SET first_name=%s, last_name=%s, login=%s, password=%s, privilege=%s, login_time=%s, logout_time=%s WHERE id=%s",
                       GetSQLValueString($_POST['first_name'], "text"),
                       GetSQLValueString($_POST['last_name'], "text"),
                       GetSQLValueString($_POST['login'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['privilege'], "text"),
                       GetSQLValueString($_POST['login_time'], "date"),
                       GetSQLValueString($_POST['logout_time'], "date"),
                       GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_Concierge, $Concierge);
  $Result1 = mysql_query($updateSQL, $Concierge) or die(mysql_error());

  $updateGoTo = "edit_staff_member.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_rsAuth = "-1";
if (isset($_GET['id'])) {
  $colname_rsAuth = $_GET['id'];
}
mysql_select_db($database_Concierge, $Concierge);
$query_rsAuth = sprintf("SELECT * FROM auth WHERE id = %s", GetSQLValueString($colname_rsAuth, "int"));
$rsAuth = mysql_query($query_rsAuth, $Concierge) or die(mysql_error());
$row_rsAuth = mysql_fetch_assoc($rsAuth);
$totalRows_rsAuth = mysql_num_rows($rsAuth);
?>
<!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>Form Update</title>

<link href="../includes/primary_layout.css" rel="stylesheet" type="text/css"/>
<style type="text/css">
#center_box {
height: 199px;
width: 183px;
padding: 0px;
left: 131px;
top: 47px;
position: absolute;
margin-top: -55px;
margin-right: auto;
margin-bottom: auto;
margin-left: -65px;
}	
</style>
</head>
<body>

<div id="wrapper">
  <div id="small-blue-box">
         <form id="center_box" name="form1" method="post" action="">
        <p> </p>
        <table width="264" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <th width="114"> </th>
            <td width="144"> </td>
          </tr>
          <tr>
            <th>First Name</th>
            <td><input name="first_name" type="text" id="first_name" value="<?php echo $row_rsAuth['first_name']; ?>" size="20" /></td>
          </tr>
          <tr>
            <th> </th>
            <td> </td>
          </tr>
          <tr>
            <th>Last Name</th>
            <td><input name="last_name" type="text" id="last_name" value="<?php echo $row_rsAuth['last_name']; ?>" size="20" /></td>
          </tr>
          <tr>
            <th> </th>
            <td> </td>
          </tr>
          <tr>
            <th>Login</th>
            <td><input name="login" type="text" id="login" value="<?php echo $row_rsAuth['login']; ?>" size="20" /></td>
          </tr>
          <tr>
            <th> </th>
            <td> </td>
          </tr>
          <tr>
            <th>Password</th>
            <td><input name="password" type="password" id="password" value="<?php echo $row_rsAuth['password']; ?>" size="20" /></td>
          </tr>
          <tr>
            <th> </th>
            <td> </td>
          </tr>
          <tr>
            <th>Privilage</th>
            <td><select name="privilege" id="privilege">
              <option value="receptionist" <?php if (!(strcmp("receptionist", $row_rsAuth['privilege']))) {echo "selected=\"selected\"";} ?>>Receptionist</option>
              <option value="suspended" <?php if (!(strcmp("suspended", $row_rsAuth['privilege']))) {echo "selected=\"selected\"";} ?>>Suspended</option>
              <option value="manager" <?php if (!(strcmp("manager", $row_rsAuth['privilege']))) {echo "selected=\"selected\"";} ?>>Manager</option>
              <option value="administrator" <?php if (!(strcmp("administrator", $row_rsAuth['privilege']))) {echo "selected=\"selected\"";} ?>>Administrator</option>
              <?php
do {  
?>
              <option value="<?php echo $row_rsAuth['privilege']?>"<?php if (!(strcmp($row_rsAuth['privilege'], $row_rsAuth['privilege']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsAuth['privilege']?></option>
              <?php
} while ($row_rsAuth = mysql_fetch_assoc($rsAuth));
  $rows = mysql_num_rows($rsAuth);
  if($rows > 0) {
      mysql_data_seek($rsAuth, 0);
  $row_rsAuth = mysql_fetch_assoc($rsAuth);
  }
?>
            </select></td>
          </tr>
          <tr>
            <th> </th>
            <td> </td>
          </tr>
          <tr>
            <th><input name="id" type="hidden" id="id" value="<?php echo $row_rsAuth['id']; ?>" />
              <input name="login_time" type="hidden" id="login_time" value="<?php echo $row_rsAuth['login_time']; ?>" />
              <input name="logout_time" type="hidden" id="logout_time" value="<?php echo $row_rsAuth['logout_time']; ?>" />
              <input type="hidden" name="MM_update" value="form1" /></th>
            <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
          </tr>
        </table>
        <p> </p>
        <p> </p>
        <p align="center"> </p>
      </form>
  </div>
</div>
  <?php include("../includes/footer.inc"); ?>
</div>
</body>
</html>

 

And the require being used simply introduces the database connect info:

require_once ../Connections/Concierge.php =

 

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_Concierge = "localhost";
$database_Concierge = "database";
$username_Concierge = "username";
$password_Concierge = "password";
$Concierge = mysql_pconnect($hostname_Concierge, $username_Concierge, $password_Concierge) or trigger_error(mysql_error(),E_USER_ERROR); 
?>

 

Any and all help with this is greatly appreciated. I am trying to get it all to run from the same interface rather than different pages.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.