Ver Mensaje Individual
  #7 (permalink)  
Antiguo 25/04/2013, 07:36
elheraldonet
 
Fecha de Ingreso: abril-2013
Mensajes: 8
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Consulta: Error al colocar foreach y comprobacion de registro juntos

Nuevamente gracias arros por responderme... entonces, es evidente que no estoy sabiendo aplicar el codigo , te comparto el codigo php completo con la porcion de codigo que me pasaste:

Código 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 = "index.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;
}
}

// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset(
$_POST[$MM_flag])) {
  
$MM_dupKeyRedirect="panelerror.php";
  
$loginUsername = $_POST['fecha'];
  
$usuariod = $_POST['us'];
  
$LoginRS__query = sprintf("SELECT fecha, us FROM mi_tabla WHERE fecha=%s AND us=$usuariod", GetSQLValueString($loginUsername, "date"));
  
mysql_select_db($database_baseprueba, $baseprueba);
  
$LoginRS=mysql_query($LoginRS__query, $baseprueba) or die(mysql_error());
  
$loginFoundUser = mysql_num_rows($LoginRS);

  
//if there is a row in the database, the username was found - can not add the requested username
  
if($loginFoundUser){
    
$MM_qsChar = "?";
    
//append the username to the redirect page
    
if (substr_count($MM_dupKeyRedirect,"?") >=10) $MM_qsChar = "&";
    
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
    
header ("Location: $MM_dupKeyRedirect");
    exit;
  }
}

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

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
    
$values = array();
    foreach(
$_POST["id"] as $key => $value) {
        
$values[]   = "('{$_POST['id']}', '{$_POST['cantidad']}', '{$_POST['edad']}', '{$_POST['fecha']}', '{$_POST['us']}', '{$_POST['loc']}', '{$_POST['zona']}')";
        
$query = "INSERT INTO febriles (id, cantidad, edad, fecha, us, loc, zona) VALUES ".implode(',', $values);
       
       
        
mysql_select_db($database_baseprueba, $baseprueba);
        
$Result1 = mysql_query($query, $baseprueba) or die(mysql_error());
    
  
$insertGoTo = "panel.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }}
  
header(sprintf("Location: %s", $insertGoTo));
}

$colname_rs_user = "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_rs_user = $_SESSION['MM_Username'];
}
mysql_select_db($database_baseprueba, $baseprueba);
$query_rs_user = sprintf("SELECT us, nombre, inst, `level` FROM tabla_user WHERE nombre = %s", GetSQLValueString($colname_rs_user, "text"));
$rs_user = mysql_query($query_rs_user, $baseprueba) or die(mysql_error());
$row_rs_user = mysql_fetch_assoc($rs_user);
$totalRows_rs_user = mysql_num_rows($rs_user);$colname_rs_user = "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_rs_user = $_SESSION['MM_Username'];
}
mysql_select_db($database_baseprueba, $baseprueba);
$query_rs_user = sprintf("SELECT us, nombre, inst, loc, zona, `level` FROM tabla_user WHERE nombre = %s", GetSQLValueString($colname_rs_user, "text"));
$rs_user = mysql_query($query_rs_user, $baseprueba) or die(mysql_error());
$row_rs_user = mysql_fetch_assoc($rs_user);
$totalRows_rs_user = mysql_num_rows($rs_user);

mysql_select_db($database_baseprueba, $baseprueba);
$query_rs_edad = "SELECT * FROM tabla_edades";
$rs_edad = mysql_query($query_rs_edad, $baseprueba) or die(mysql_error());
$row_rs_edad = mysql_fetch_assoc($rs_edad);
$totalRows_rs_edad = mysql_num_rows($rs_edad);
?>