Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to create an update page

New Here ,
Jan 14, 2013 Jan 14, 2013

i want to create an update page using dreamweaver and record set, i succeded but it only updates the database with user id of 1. even if i login as another user with id of 3, it keeps updating the user with id of 1.please help me, a lost. below is my code:

<?php require_once('Connections/conn_login.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($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)

  $MM_referrer .= "?" . $_SERVER['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;

}

}

$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 login SET username=%s, pwd=%s, `role`=%s, firstname=%s, lastname=%s, country=%s WHERE userID=%s",

                       GetSQLValueString($_POST['email'], "text"),

                       GetSQLValueString($_POST['pwd'], "text"),

                       GetSQLValueString($_POST['role'], "text"),

                       GetSQLValueString($_POST['firstname'], "int"),

                       GetSQLValueString($_POST['lastname'], "int"),

                       GetSQLValueString($_POST['country'], "int"),

                       GetSQLValueString($_POST['id1'], "int"));

  mysql_select_db($database_conn_login, $conn_login);

  $Result1 = mysql_query($updateSQL, $conn_login) or die(mysql_error());

  $updateGoTo = "index.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";

    $updateGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $updateGoTo));

}

$colname_Recordset1 = "-1";

if (isset($_GET['userID'])) {

  $colname_Recordset1 = $_GET['userID'];

  $_SESSION['userID'] = $_GET['userID'];

 

}

$colname_Recordset1 = "-1";

if (isset($_GET[''])) {

  $colname_Recordset1 = $_GET[''];

}

mysql_select_db($database_conn_login, $conn_login);

$query_Recordset1 = sprintf("SELECT userID, username, pwd, `role`, firstname, lastname FROM login WHERE userID = %s", GetSQLValueString($colname_Recordset1, "int"));

$Recordset1 = mysql_query($query_Recordset1, $conn_login) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

?>

<!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>Scuba2u</title>

<link href="styles.css" rel="stylesheet" type="text/css" />

</head>

<body>

<?php include('headerScuba2u.php'); ?>

<div id="main">

    <div id="left">

      <h1>Registration Form</h1>

      <fieldset>

        <legend>Register for our website</legend>

        <form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">

          <p>

            <label for="firstname">First Name</label>

            <input name="firstname" type="text" id="firstname" size="30" maxlength="40" />

          </p>

          <p>Last Name

            <label for="lastname"></label>

            <input name="lastname" type="text" id="lastname" size="30" maxlength="40" />

          </p>

          <p>Country

            <input name="country" type="text" id="country" size="30" maxlength="30" />

          </p>

          <p>Email

            <label for="email"></label>

            <input name="email" type="text" id="email" size="60" maxlength="60" />

          </p>

          <p>Password

            <label for="pwd"></label>

            <input name="pwd" type="password" id="pwd" size="10" maxlength="10" />

          </p>

          <p>

            <input name="role" type="hidden" id="role" value="guest" />

            <input name="id1" type="hidden" id="id1" value="<?php echo $row_Recordset1['userID']; ?>" />

            <input type="submit" name="submit" id="submit" value="Register" />

          </p>

          <input type="hidden" name="MM_update" value="form1" />

        </form>

      </fieldset>

    </div>

</div>

<?php include('footerScuba2u.php'); ?>

</body>

</html>

<?php

mysql_free_result($Recordset1);

?>

TOPICS
Server side applications
502
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 14, 2013 Jan 14, 2013
LATEST

Temporarily change your id1 field from a hidden field to a text field so you can see if it is being set correctly for the logged in user.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines