PHP - Actualizar contenido de una Tabla, PHP y MSQL

 
Vista:
Imágen de perfil de Robinson

Actualizar contenido de una Tabla, PHP y MSQL

Publicado por Robinson (41 intervenciones) el 30/11/2015 03:00:19
Buenas amigos gusto en saludarles,

Vengo por acá buscando del apoyo de ustedes:

Tengo esta tabla y quisiera poder actualizar los registros de la misma:


Tabla-01

Esta tabla la estoy llamando y filtrando por regiones, en este caso solo estoy llamando a la region Andes

BD-My-Sql-01

Como los comento, quisiera poder actualizar los datos, seria ideal que fuera en otra pagina o no se que pueden sugerir ustedes,

Les dejo parte del código

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php require_once('../../Connections/local.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;
}
}
 
$colname_gcni2015 = "-1";
if (isset($_GET['Region'])) {
  $colname_gcni2015 = $_GET['Region'];
}
mysql_select_db($database_local, $local);
$query_gcni2015 = sprintf("SELECT * FROM `gcni nacional` WHERE Region = 'Andes'", GetSQLValueString($colname_gcni2015, "text"));
$gcni2015 = mysql_query($query_gcni2015, $local) or die(mysql_error());
$row_gcni2015 = mysql_fetch_assoc($gcni2015);
$totalRows_gcni2015 = mysql_num_rows($gcni2015);
?>
<?php

El front:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<table border="1" align="center" bgcolor="#FFFFFF" width="1280">
  <tr bgcolor="#E0E0E0" align="center" height="30">
 
    <td width="280" height="25"><strong>Indicador</strong></td>
    <td><strong>Año</strong></td>
    <td><strong>Region</strong></td>
    <td><strong>CDS</strong></td>
    <td><strong>Enero</strong></td>
    <td><strong>Febrero</strong></td>
    <td><strong>Marzo</strong></td>
    <td><strong>Abril</strong></td>
    <td><strong>Mayo</strong></td>
    <td><strong>Junio</strong></td>
    <td><strong>Julio</strong></td>
    <td><strong>Agosto</strong></td>
    <td><strong>Septiembre</strong></td>
    <td><strong>Octubre</strong></td>
    <td><strong>Noviembre</strong></td>
    <td><strong>Diciembre</strong></td>
  </tr>
 
  <?php do { ?>
    <tr align="center" height="20" >
      <td bgcolor="#E0E0E0" align="left"><?php echo $row_gcni2015['Id'];  ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['year']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['Region']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['CDS']; ?>&nbsp;</td>
      <td><?php echo $row_gcni2015['Enero']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['Febrero']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['Marzo']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['Abril']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['Mayo']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['Junio']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['Julio']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['Agosto']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['Septiembre']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['Octubre']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['Noviembre']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['Diciembre']; ?>&nbsp; </td>
 
    </tr>
 
    <?php } while ($row_gcni2015 = mysql_fetch_assoc($gcni2015)); ?>
 
</table>
 
 
</body>
</html>
<?php
mysql_free_result($gcni2015);
?>
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
sin imagen de perfil

Actualizar contenido de una Tabla, PHP y MSQL

Publicado por cesar (24 intervenciones) el 03/12/2015 03:59:47
deberías ser mas especifico de lo que quieres lograr amigo según lo que entendí eso se soluciona con un simple update
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Robinson

Actualizar contenido de una Tabla, PHP y MSQL

Publicado por Robinson (41 intervenciones) el 10/12/2015 22:42:04
Hola, ya hice el update, pero no logra actualizar la tabla,

Al intentar actualizar regresa al archivo pero sin actualizar.

Les dejo parte del código:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
$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 `cantidad de cursos nacional` SET `year`='%s', Region='%s', Enero='%s', Febrero='%s', Marzo='%s', Abril='%s', Mayo='%s', Junio='%s', Julio='%s', Agosto='%s', Septiembre='%s', Octubre='%s', Noviembre='%s', Diciembre='%s' WHERE ID_Curso='%s'",
                       GetSQLValueString($_POST['Enero'], "int"),
                       GetSQLValueString($_POST['Febrero'], "int"),
                       GetSQLValueString($_POST['Marzo'], "int"),
                       GetSQLValueString($_POST['Abril'], "int"),
                       GetSQLValueString($_POST['Mayo'], "int"),
                       GetSQLValueString($_POST['Junio'], "int"),
                       GetSQLValueString($_POST['Julio'], "int"),
                       GetSQLValueString($_POST['Agosto'], "int"),
                       GetSQLValueString($_POST['Septiembre'], "int"),
                       GetSQLValueString($_POST['Octubre'], "int"),
                       GetSQLValueString($_POST['Noviembre'], "int"),
                       GetSQLValueString($_POST['Diciembre'], "int"),
                       GetSQLValueString($_POST['ID_Curso'], "varchar"),
					   GetSQLValueString($_POST['year'], "year"),
                       GetSQLValueString($_POST['Region'], "varchar"));
 
  mysql_select_db($database_local, $local);
  $Result1 = mysql_query($updateSQL, $local) or die(mysql_error());
 
  $updateGoTo = "gcniandes.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}
 
$colname_gcni2015 = "-1";
if (isset($_GET['Region'])) {
  $colname_gcni2015 = $_GET['Region'];
}
 
mysql_select_db($database_local, $local);
$query_gcni2015 = sprintf("SELECT * FROM `gcni nacional` WHERE `Region`= 'Andes'", GetSQLValueString($colname_gcni2015, "Region"));
$gcni2015 = mysql_query($query_gcni2015, $local) or die(mysql_error());
$row_gcni2015 = mysql_fetch_assoc($gcni2015);
$totalRows_gcni2015 = mysql_num_rows($gcni2015);
 
?>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Actualizar contenido de una Tabla, PHP y MSQL

Publicado por xve (6935 intervenciones) el 11/12/2015 08:12:16
Has hecho un :

1
echo $updateSQL;

haber si todos los campos se rellenan correctamente?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Robinson

Actualizar contenido de una Tabla, PHP y MSQL

Publicado por Robinson (41 intervenciones) el 11/12/2015 14:15:32
Esto es lo que tengo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
 
<table border="1" align="center" bgcolor="#FFFFFF" width="1280">
  <tr bgcolor="#E0E0E0" align="center" height="30">
 
    <td width="280" height="25"><strong>Indicador</strong></td>
    <td><strong>Año</strong></td>
    <td><strong>Region</strong></td>
    <td><strong>CDS</strong></td>
    <td><strong>Ene</strong></td>
    <td><strong>Feb</strong></td>
    <td><strong>Mar</strong></td>
    <td><strong>Abr</strong></td>
    <td><strong>May</strong></td>
    <td><strong>Jun</strong></td>
    <td><strong>Jul</strong></td>
    <td><strong>Ago</strong></td>
    <td><strong>Sep</strong></td>
    <td><strong>Oct</strong></td>
    <td><strong>Nov</strong></td>
    <td><strong>Dic</strong></td>
 
  </tr>
 
 
 
  <?php do { ?>
    <tr align="center" height="20" >
      <td bgcolor="#E0E0E0" align="left"><?php echo $row_gcni2015['Id'];  ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['year']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['Region']; ?>&nbsp; </td>
      <td><?php echo $row_gcni2015['CDS']; ?>&nbsp;</td>
      <td><input type="text" name="Enero" value="<?php echo htmlentities($row_gcni2015['Enero'], ENT_COMPAT, 'utf-8'); ?>" size="1"></td>
      <td><input type="text" name="Febrero" value="<?php echo htmlentities($row_gcni2015['Febrero'], ENT_COMPAT, 'utf-8'); ?>" size="1"></td>
      <td><input type="text" name="Marzo" value="<?php echo htmlentities($row_gcni2015['Marzo'], ENT_COMPAT, 'utf-8'); ?>" size="1"></td>
      <td><input type="text" name="Abril" value="<?php echo htmlentities($row_gcni2015['Abril'], ENT_COMPAT, 'utf-8'); ?>" size="1"></td>
      <td><input type="text" name="Mayo" value="<?php echo htmlentities($row_gcni2015['Mayo'], ENT_COMPAT, 'utf-8'); ?>" size="1"></td>
      <td><input type="text" name="Junio" value="<?php echo htmlentities($row_gcni2015['Junio'], ENT_COMPAT, 'utf-8'); ?>" size="1"> </td>
      <td><input type="text" name="Julio" value="<?php echo htmlentities($row_gcni2015['Julio'], ENT_COMPAT, 'utf-8'); ?>" size="1"></td>
      <td><input type="text" name="Agosto" value="<?php echo htmlentities($row_gcni2015['Agosto'], ENT_COMPAT, 'utf-8'); ?>" size="1"></td>
      <td><input type="text" name="Septiembre" value="<?php echo htmlentities($row_gcni2015['Septiembre'], ENT_COMPAT, 'utf-8'); ?>" size="1"></td>
      <td><input type="text" name="Octubre" value="<?php echo htmlentities($row_gcni2015['Octubre'], ENT_COMPAT, 'utf-8'); ?>" size="1"></td>
      <td><input type="text" name="Noviembre" value="<?php echo htmlentities($row_gcni2015['Noviembre'], ENT_COMPAT, 'utf-8'); ?>" size="1"></td>
      <td><input type="text" name="Diciembre" value="<?php echo htmlentities($row_gcni2015['Diciembre'], ENT_COMPAT, 'utf-8'); ?>" size="1"></td>
 
    </tr>
 
    <?php } while ($row_gcni2015 = mysql_fetch_assoc($gcni2015)); ?>
 
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table>
    <tr valign="baseline">
      <td nowrap align="center">&nbsp;</td>
      <td><input type="submit" value="Actualizar registro"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1">
  <input type="hidden" name="ID_Curso" value="<?php echo $row_gcni2015['ID_Curso']; ?>">
</form>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Actualizar contenido de una Tabla, PHP y MSQL

Publicado por xve (6935 intervenciones) el 11/12/2015 16:33:23
Prueba ha hacer el echo que te he comentado... haber que valores recibe...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar