Foros del Web » Programando para Internet » PHP »

editar-borrar en tabla

Estas en el tema de editar-borrar en tabla en el foro de PHP en Foros del Web. Hola, tengo una tabla, la cual me muestra los proyectos que tengo en una db, Código PHP: <?php  require_once( 'Connections/localhost.php' );  ?> <?php if (! function_exists ...
  #1 (permalink)  
Antiguo 26/12/2011, 09:21
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
editar-borrar en tabla

Hola, tengo una tabla, la cual me muestra los proyectos que tengo en una db,

Código PHP:
<?php require_once('Connections/localhost.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;
}
}

$currentPage $_SERVER["PHP_SELF"];

$maxRows_proyectos 15;
$pageNum_proyectos 0;
if (isset(
$_GET['pageNum_proyectos'])) {
  
$pageNum_proyectos $_GET['pageNum_proyectos'];
}
$startRow_proyectos $pageNum_proyectos $maxRows_proyectos;

mysql_select_db($database_localhost$localhost);
$query_proyectos "SELECT * FROM proyectos ORDER BY noper ASC";
$query_limit_proyectos sprintf("%s LIMIT %d, %d"$query_proyectos$startRow_proyectos$maxRows_proyectos);
$proyectos mysql_query($query_limit_proyectos$localhost) or die(mysql_error());
$row_proyectos mysql_fetch_assoc($proyectos);

if (isset(
$_GET['totalRows_proyectos'])) {
  
$totalRows_proyectos $_GET['totalRows_proyectos'];
} else {
  
$all_proyectos mysql_query($query_proyectos);
  
$totalRows_proyectos mysql_num_rows($all_proyectos);
}
$totalPages_proyectos ceil($totalRows_proyectos/$maxRows_proyectos)-1;

$queryString_proyectos "";
if (!empty(
$_SERVER['QUERY_STRING'])) {
  
$params explode("&"$_SERVER['QUERY_STRING']);
  
$newParams = array();
  foreach (
$params as $param) {
    if (
stristr($param"pageNum_proyectos") == false && 
        
stristr($param"totalRows_proyectos") == false) {
      
array_push($newParams$param);
    }
  }
  if (
count($newParams) != 0) {
    
$queryString_proyectos "&" htmlentities(implode("&"$newParams));
  }
}
$queryString_proyectos sprintf("&totalRows_proyectos=%d%s"$totalRows_proyectos$queryString_proyectos);
?>
<!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>Documento sin título</title>
<style type="text/css">
body,td,th {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 9px;
}
</style>
</head>

<body>
<table width="950" border="0" align="center" whidth="950">
  <tr align="center">
    <td><strong>NOMBRE DE PROYECTO</strong></td>
    <td><p><strong>N&deg; OPE.</strong></p></td>
    <td><strong>ADMINISTRADOR</strong></td>
    <td><strong>TIPO</strong></td>
    <td><strong>CORREO</strong></td>
    <td><strong>MODIFICACIÓN</strong></td>
    <td><strong>ELIMINAR</strong></td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_proyectos['proy']; ?></td>
      <td align="center"><?php echo $row_proyectos['noper']; ?></td>
      <td><?php echo $row_proyectos['admpro']; ?></td>
      <td><?php echo $row_proyectos['pert']; ?></td>
      <td><?php echo $row_proyectos['correo']; ?></td>
      <td align="center"><form id="editar" name="editar" method="post" action="editar_proyecto.php">
        <input type="submit" name="editar" id="editar" value="Modificar" />
      </form></td>
      <td align="center"><form id="borrar" name="borrar" method="post" action="">
        <input type="submit" name="borrar" id="borrar" value="Eliminar" />
      </form></td>
    </tr>
    <?php } while ($row_proyectos mysql_fetch_assoc($proyectos)); ?>
</table>
<table width="950" border="0" align="center">
  <tr align="center">
    <td width="50"><?php if ($pageNum_proyectos 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_proyectos=%d%s"$currentPage0$queryString_proyectos); ?>"><img src="imagenes/First.gif" /></a>
        <?php // Show if not first page ?></td>
    <td width="50"><?php if ($pageNum_proyectos 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_proyectos=%d%s"$currentPagemax(0$pageNum_proyectos 1), $queryString_proyectos); ?>"><img src="imagenes/Previous.gif" /></a>
        <?php // Show if not first page ?></td>
    <td>&nbsp;</td>
    <td width="50"><?php if ($pageNum_proyectos $totalPages_proyectos) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_proyectos=%d%s"$currentPagemin($totalPages_proyectos$pageNum_proyectos 1), $queryString_proyectos); ?>"><img src="imagenes/Next.gif" /></a>
      <?php // Show if not last page ?></td>
    <td width="50"><?php if ($pageNum_proyectos $totalPages_proyectos) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_proyectos=%d%s"$currentPage$totalPages_proyectos$queryString_proyectos); ?>"><img src="imagenes/Last.gif" /></a>
      <?php // Show if not last page ?></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result
($proyectos);
?>
y como ven, tambien hay dos botones, uno de editar y otro para borrar el proyecto.
  #2 (permalink)  
Antiguo 26/12/2011, 09:22
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: editar-borrar en tabla

Mi problema es que no logro que la pagina editar_proyecto.php me tome los datos de la linea que quiero modificar...

Código PHP:
<?php require_once('Connections/localhost.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;
}
}

$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 proyectos SET noper=%s, admpro=%s, contacto=%s, region=%s, comuna=%s, direccion=%s, telefono=%s, correo=%s, pert=%s WHERE proy=%s",
                       
GetSQLValueString($_POST['noper'], "text"),
                       
GetSQLValueString($_POST['admpro'], "text"),
                       
GetSQLValueString($_POST['contacto'], "text"),
                       
GetSQLValueString($_POST['region'], "text"),
                       
GetSQLValueString($_POST['comuna'], "text"),
                       
GetSQLValueString($_POST['direccion'], "text"),
                       
GetSQLValueString($_POST['telefono'], "text"),
                       
GetSQLValueString($_POST['correo'], "text"),
                       
GetSQLValueString($_POST['pert'], "text"),
                       
GetSQLValueString($_POST['proy'], "text"));

  
mysql_select_db($database_localhost$localhost);
  
$Result1 mysql_query($updateSQL$localhost) or die(mysql_error());

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

mysql_select_db($database_localhost$localhost);
$query_proyectos "SELECT * FROM proyectos ORDER BY noper ASC";
$proyectos mysql_query($query_proyectos$localhost) or die(mysql_error());
$row_proyectos mysql_fetch_assoc($proyectos);
$totalRows_proyectos mysql_num_rows($proyectos);
?>
<!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>Documento sin título</title>
</head>

<body>
<form action="<?php echo $editFormAction?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Proyecto:</td>
      <td><?php echo $row_proyectos['proy']; ?></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">N.Ope,:</td>
      <td><input type="text" name="noper" value="<?php echo htmlentities($row_proyectos['noper'], ENT_COMPAT'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Administrador:</td>
      <td><input type="text" name="admpro" value="<?php echo htmlentities($row_proyectos['admpro'], ENT_COMPAT'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Contacto:</td>
      <td><input type="text" name="contacto" value="<?php echo htmlentities($row_proyectos['contacto'], ENT_COMPAT'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Regi&oacute;n:</td>
      <td><input type="text" name="region" value="<?php echo htmlentities($row_proyectos['region'], ENT_COMPAT'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Comuna:</td>
      <td><input type="text" name="comuna" value="<?php echo htmlentities($row_proyectos['comuna'], ENT_COMPAT'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Direcci&oacute;n:</td>
      <td><input type="text" name="direccion" value="<?php echo htmlentities($row_proyectos['direccion'], ENT_COMPAT'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Telefono:</td>
      <td><input type="text" name="telefono" value="<?php echo htmlentities($row_proyectos['telefono'], ENT_COMPAT'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Correo:</td>
      <td><input type="text" name="correo" value="<?php echo htmlentities($row_proyectos['correo'], ENT_COMPAT'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Pertenece a:</td>
      <td><input type="text" name="pert" value="<?php echo htmlentities($row_proyectos['pert'], ENT_COMPAT'utf-8'); ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Actualizar registro" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1" />
  <input type="hidden" name="proy" value="<?php echo $row_proyectos['proy']; ?>" />
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result
($proyectos);
?>
Con respcto al boton Eliminar, tampoco se como hacerlo... pero ya encontrare la forma, espero...
  #3 (permalink)  
Antiguo 26/12/2011, 13:11
Avatar de jolie_girl  
Fecha de Ingreso: agosto-2008
Ubicación: mexico
Mensajes: 346
Antigüedad: 15 años, 7 meses
Puntos: 10
Respuesta: editar-borrar en tabla

debes poner el error que te sale
__________________
Solicito colaboradoras para proyecto social media largo plazo. Manda mp
  #4 (permalink)  
Antiguo 26/12/2011, 18:02
 
Fecha de Ingreso: noviembre-2011
Mensajes: 121
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: editar-borrar en tabla

nada pos, no sale ningun error porque no se como debo hacer esto...

he logrado hacer muchas cosas por medio de Dreamweaver, pero hay otras que no he logrado...

Etiquetas: html, mysql, sql, tabla
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:54.