Cita:
Iniciado por p414
donde ocupas eso??? sabes que hace??? de no ser así te recomiendo que leeas el manual de PHP
Código PHP:
Ver originalNotice: Undefined index: action in C:\xampp\htdocs\proyecto\editar.php on line 7
aqui te dice que no has definido una variable llamada action... porque no nos muestras algo de código...
yo a mysql_affected_rows lo utilizo para que me de las ultimas filas afectadas por el UPDATE osea las editadas. paso algo de codigo:
Concexion:
Código PHP:
<?php
$conexion = mysql_connect("localhost", "gonza", "") or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db("practica", $conexion);
?>
Funciones:
Código PHP:
<?php
function getParam($param, $default) {
$result = $default;
if (isset($param)) {
$result = (get_magic_quotes_gpc()) ? $param : addslashes($param);
}
return $result;
}
function sqlValue($value, $type) {
$value = get_magic_quotes_gpc() ? stripslashes($value) : $value;
$value = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($value) : mysql_escape_string($value);
switch ($type) {
case "text":
$value = ($value != "") ? "'" . $value . "'" : "NULL";
break;
case "int":
$value = ($value != "") ? intval($value) : "NULL";
break;
case "double":
$value = ($value != "") ? "'" . doubleval($value) . "'" : "NULL";
break;
case "date":
$value = ($value != "") ? "'" . $value . "'" : "NULL";
break;
}
return $value;
}
?>
Editar que estoy utilizando ahora:
Código PHP:
<?php
require("include/conexion.php");
require("include/funciones.php");
$idempresa = getParam($_GET["id"], "-1");
$action = getParam($_GET["action"], "");
if ($action == "edit") {
$idempresa = sqlValue($_POST["id"], "int");
$nombre = sqlValue($_POST["nombre"], "text");
$direccion = sqlValue($_POST["direccion"], "text");
$telefono = sqlValue($_POST["telefono"], "int");
$sql = "UPDATE empresa SET ";
$sql.= "nombre=".$nombre.", direccion=".$direccion.", telefono=".$telefono." ";
$sql.= "WHERE id=".$idempresa;
mysql_query($sql, $conexion);
header("location: listado.php");
}
$sql = "SELECT * FROM empresa WHERE id = ".sqlValue($idempresa, "int");
$queEmp = mysql_query($sql, $conexion);
$rsEmp = mysql_fetch_assoc($queEmp);
$total = mysql_num_rows($queEmp);
if ($total == 0) {
header("location: listado.php");
exit;
}
?>
<!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=UTF-8" />
<title>PHP con MySQL: Editar datos en MySQL</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h3>Editar Empresa</h3>
<form method="post" id="frEmpresa" action="editar.php?action=edit">
<label for="nombre">Nombre</label>
<input type="text" id="nombre" name="nombre" value="<?php echo $rsEmp["nombre"]; ?>" />
<br />
<label for="direccion">Dirección</label>
<input type="text" id="direccion" name="direccion" value="<?php echo $rsEmp["direccion"]; ?>" />
<br />
<label for="telefono">Telefono</label>
<input type="text" id="telefono" name="telefono" value="<?php echo $rsEmp["telefono"]; ?>" />
<br />
<label for="bts"> </label>
<button type="submit">Guardar</button>
<button type="reset">Limpiar</button>
<input type="hidden" id="id" name="id" value="<?php echo $rsEmp["id"]; ?>" />
</form>
</body>
</html>
Listado:
Código PHP:
<?php
require("include/conexion.php");
require("include/funciones.php");
$query = "SELECT * FROM empresa ORDER BY nombre ASC";
$queEmp = mysql_query($query, $conexion);
?>
<!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=UTF-8" />
<title>Listado de Empresas</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h3>Listado de Empresas</h3>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Nombre</th>
<th>Dirección</th>
<th> </th>
</tr>
<?php while ($rsEmp = mysql_fetch_assoc($queEmp)) { ?>
<tr>
<td><?php echo $rsEmp['nombre']; ?></td>
<td><?php echo $rsEmp['direccion']; ?></td>
<td><a href="editar.php?id=<?php echo $rsEmp['id']; ?>">Editar</a></td>
</tr>
<?php } ?>
</table>
<p> </p>
</body>
</html>
ahora todo esto solo me tira un error: Notice: Undefined index: action in C:\xampp\htdocs\proyecto\editar.php on line 6