ibakir 0 Light Poster

i would like to write a function if that user id who do a post equal the same user id who logged in then he can after a while edit again his own post , then if its match go to the update page to make the edit ; http://www.dalilack.com/marketFormUpdate.php?Id=11
if not : go to log in page to write his own user name and pass for that post he clicked edit on it ; http://www.dalilack.com/marketList.php

now this function where and how i supposed to write it , in MarketFormUpdate page Or marketList page ??
although i have write this lil code

$user_id = 0;//the id number who logged in right now and can edit his old info
if($user_id != $row_formUpdate[0]['idAdmin']){
  echo "this is not your post";
  exit();
} else {
  echo "you can change your post";
}

to check if admin id equal the post id that this post back to him
MySQL is :
http://www.dalilack.com/info.jpg
http://www.dalilack.com/admin.jpg

here's the code and i don't really know what missing

<?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/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 explorers SET name=%s, email=%s, product=%s, price=%s, phoneNumber=%s, comments=%s WHERE Id=%s",
                       GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['product'], "text"),
                       GetSQLValueString($_POST['price'], "text"),
                       GetSQLValueString($_POST['phoneNumber'], "text"),
                       GetSQLValueString($_POST['comments'], "text"),
                       GetSQLValueString($_POST['Id'], "int"));

  mysql_select_db($database_dalilack, $dalilack);
  $Result1 = mysql_query($updateSQL, $dalilack) or die(mysql_error());

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

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_dalilack, $dalilack);
$query_product = "SELECT * FROM states";
$product = mysql_query($query_product, $dalilack) or die(mysql_error());
$row_product = mysql_fetch_assoc($product);
$totalRows_product = mysql_num_rows($product);

$colname_formUpdate = "-1";
if (isset($_GET['Id'])) {
  $colname_formUpdate = $_GET['Id'];
}
mysql_select_db($database_dalilack, $dalilack);
$query_formUpdate = sprintf("SELECT Id, idAdmin, name, email, product, price, phoneNumber, comments FROM explorers WHERE Id = %s", GetSQLValueString($colname_formUpdate, "int"));
$formUpdate = mysql_query($query_formUpdate, $dalilack) or die(mysql_error());
$row_formUpdate = mysql_fetch_assoc($formUpdate);
$totalRows_formUpdate = mysql_num_rows($formUpdate);

$colname_formUpdate = "-1";
if (isset($_GET['Id'])) {
  $colname_formUpdate = $_GET['Id'];
}
mysql_select_db($database_dalilack, $dalilack);
$query_formUpdate = sprintf("SELECT Id, name, email, product, price, phoneNumber, comments, idAdmin, `admin`.adminId FROM explorers, `admin` WHERE Id = %s AND explorers.idAdmin = `admin`.adminId", GetSQLValueString($colname_formUpdate, "int"));
$formUpdate = mysql_query($query_formUpdate, $dalilack) or die(mysql_error());
$row_formUpdate = mysql_fetch_assoc($formUpdate);
$totalRows_formUpdate = mysql_num_rows($formUpdate);
$user_id = 0;//the id number who logged in right now and can edit his old info
if($user_id != $row_formUpdate[0]['idAdmin']){
  echo "this is not your post";
  exit();
} else {
  echo "you can change your post";
}
$colname_formUpdate = "-1";
if (isset($_GET['Id'])) {
  $colname_formUpdate = $_GET['Id'];
}

?>

thanks Guys for helping

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.