PHP - insertar registro

 
Vista:

insertar registro

Publicado por Ruth (3 intervenciones) el 07/06/2007 16:12:45
Hola quisiera saber si me pueden ayudar, estoy programando en php (con dreamweaver) una pagina que jala los registros de la base de datos, genera un numero consecutivo y lo vuelve a insertar pero la pagina me sale en blanco y cuando logro que salga no hace lo que deberia

Les dejo el codigo (le quite lo del principio para que no fuera tan largo)

<?php
/*$arrord = array($totalRows_empresa => array('dispnum'=>$_SESSION['MM_UserDispNum'],
'empresa'=>$row_empresa['empresa'],
'per_num'=>$row_empresa['person_id'],
'card_num'=>$row_empresa['card_num'],
'importe'=>$row_empresa['monto']));*/

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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"] == "form2")) {
$insertSQL = sprintf("INSERT INTO disp_enc (empresa, total, `fecha carga`, status) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['empresa'], "text"),
GetSQLValueString($_POST['total'], "double"),
GetSQLValueString($_POST['fecha'], "date"),
GetSQLValueString($_POST['status'], "text"));

mysql_select_db($database_HcH, $HcH);
$Result1 = mysql_query($insertSQL, $HcH) or die(mysql_error());
$Result2 = mysql_query('Select last_insert_ID() as disp from disp_enc;',$HcH) or die(mysql_error());
$row_ID = mysql_fetch_assoc($Result2);
$_SESSION['MM_UserDispNum'] = $row_ID['disp'];

/* $cont = 0;
do {
$cont = $cont + 1;
$insertSQL = sprintf("INSERT INTO dispersion (dispnum, empresa, person_num, card_num, importe) VALUES (%s, %s, %s, %s, %s)",
intval($arrord[$cont]['dispnum']),
"'".$arrord[$cont]['empresa']."'",
"'".$arrord[$cont]['per_num']."'",
"'".$arrord[$cont]['card_num']."'",
intval($arrord[$cont]['importe']));

mysql_select_db($database_HcH, $HcH);
$Result1 = mysql_query($insertSQL, $HcH) or die(mysql_error());
} while ($cont < $totalRows_empresa); */

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

$colname_encabezado = "-1";
if (isset($_GET['empresa'])) {
$colname_encabezado = (get_magic_quotes_gpc()) ? $_GET['empresa'] : addslashes($_GET['empresa']);
}
mysql_select_db($database_HcH, $HcH);
$query_encabezado = sprintf("SELECT * FROM disp_enc WHERE empresa = '%s'", $colname_encabezado);
$encabezado = mysql_query($query_encabezado, $HcH) or die(mysql_error());
$row_encabezado = mysql_fetch_assoc($encabezado);
$totalRows_encabezado = mysql_num_rows($encabezado);

$colname_empresa = "-1";
if (isset($_POST['MM_UserEmpresa'])) {
$colname_empresa = (get_magic_quotes_gpc()) ? $_POST['MM_UserEmpresa'] : addslashes($_POST['MM_UserEmpresa']);
}
mysql_select_db($database_HcH, $HcH);
$query_empresa = sprintf("SELECT * FROM disp_enc WHERE empresa = '%s'", $colname_empresa);
$empresa = mysql_query($query_empresa, $HcH) or die(mysql_error());
$row_empresa = mysql_fetch_assoc($empresa);
$totalRows_empresa = mysql_num_rows($empresa);
}

$periodo = "-1";
if (isset($_SESSION['MM_UserPeriodo'])) {
$periodo = (get_magic_quotes_gpc()) ? $_SESSION['MM_UserPeriodo'] : addslashes($_SESSION['MM_UserPeriodo']);
}

mysql_select_db($database_HcH, $HcH);
$query_empresa = sprintf("SELECT * FROM monto_dips WHERE empresa = '$colname_empresa' AND periodo_pago = '$periodo' ORDER BY person_id ASC");
$empresa = mysql_query($query_empresa, $HcH) or die(mysql_error());
$row_empresa = mysql_fetch_assoc($empresa);
$totalRows_empresa = mysql_num_rows($empresa);


$hoy=date('Y-m-d');
$conf='1';

?>

<!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=iso-8859-1" />
<title>Crear Archivo de Dispersion</title><style type="text/css">
<!--
body {
background-color: #EDEFEF;
}
.Estilo8 {font-size: 14px; font-family: Arial, Helvetica, sans-serif; font-weight: bold; color: #FFFFFF; }
.Estilo10 {font-family: Arial, Helvetica, sans-serif; font-weight: bold; color: #0000CC; }
.Estilo11 { font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
font-weight: bold;
}
.Estilo6 {font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #000099; }
-->
</style></head>

<body>

<p align="center"><img src="../Imagenes/hchlogo.jpg" alt="logo" width="628" height="110" /></p>
<p align="center"> </p>
<div align="center">
<div align="center">
<table width="749" border="0">
<tr>
<td width="493"><div align="left"></div></td>
<td width="121"><div align="center" class="Estilo6">
<div align="center"><a href="../Accesos/menu.php">Menu Anterior</a> </div>
</div></td>
<td width="121"><div align="center"><a href="<?php echo $logoutAction ?>" class="Estilo6">Cerrar Sesión</a></div></td>
</tr>
</table>
</div>
</div>
<p align="center"> </p>

<form method="post" name="form2" action="<?php echo $editFormAction; ?>">
<table width="335" border="1" align="center" bgcolor="#ffe4a2">
<!--DWLayoutTable-->
<tr valign="baseline">
<td width="112" height="26" align="right" nowrap bgcolor="#CC9966"><div align="center" class="Estilo8">
<div align="left">Empresa:</div>
</div></td>
<td width="433" valign="top" bgcolor="#ffe4a2"><?php echo $row_empresa['empresa']; ?></td>
</tr>
<tr valign="baseline">
<td height="26" align="right" nowrap bgcolor="#CC9966"><div align="center" class="Estilo8">
<div align="left">Total:</div>
</div></td>
<td valign="top" bgcolor="#ffe4a2"><?php echo $_SESSION['suma']; ?></td>
</tr>
<tr valign="baseline">
<td height="26" align="right" nowrap bgcolor="#CC9966"><div align="center" class="Estilo8">
<div align="left">Fecha carga:</div>
</div></td>
<td valign="top" bgcolor="#ffe4a2"><?php echo $hoy; ?></td>
</tr>
<tr valign="baseline">
<td height="26" align="right" nowrap bgcolor="#CC9966"><div align="center" class="Estilo8">
<div align="left">Status:</div>
</div></td>
<td valign="top" bgcolor="#ffe4a2"><?php echo $conf; ?></td>
</tr>
</table>

<?php /*$cont=0;


$cont=$cont+1;
$arrord[$cont]['dispnum'] = $_SESSION['MM_UserDispNum'];
$arrord[$cont]['empresa'] = $row_empresa['empresa'];
$arrord[$cont]['per_num'] = $row_empresa['person_id'];
$arrord[$cont]['card_num'] = $row_empresa['card_num'];
$arrord[$cont]['importe'] = $row_empresa['monto'];

} while ($cont < $totalRows_empresa;*/ ?>
<p> </p>
<div align="center">
<input name="submit" type="submit" value="Insertar registro" action="archivodet.php" />
<input type="hidden" name="empresa" value="<?php echo $row_empresa['empresa']; ?>">
<input type="hidden" name="fecha" value="<?php echo $hoy; ?>">
<input type="hidden" name="total" value="<?php echo $_SESSION['suma']; ?>">
<input type="hidden" name="status" value="<?php echo $conf; ?>">
<input type="hidden" name="MM_insert" value="form2">
</div>
</form>
</body>
</html>
<?php
mysql_free_result($encabezado);

mysql_free_result($empresa);
mysql_free_result($Result2);
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder